This is a discussion on Multiple values in a form option field within the PHP General forums, part of the PHP Programming Forums category; I have a php page that has a web form on it. I do a query to populate the options ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have a php page that has a web form on it.
I do a query to populate the options in a drop down box in the form. [code] <select size="1" name="customer"> <?PHP while($query_data1=mysql_fetch_row($result1)){ echo"<option value='$query_data1[0]'>$query_data1[1]</option>"; } ?> [code] $query_data1[0] is a userID number $query_data1[1] is the user's Email address So when the user selects an email addres from the drop down box, the userID is stored and later writen to a database. What I now need to do is store not only the userID but the email address as well. Is there a way using a form to store 2 values using one drop down box? So basically I want to store the userID and the Email address to a variable in the form so that both may be written to different fields in the database later. Jeff |
|
|||
|
Hello, See Below.
-----Original Message----- From: Jeff McKeon [mailto:jmckeon@telaurus.com] Sent: Thursday, November 13, 2003 2:05 PM To: php-general@lists.php.net Subject: [php] Multiple values in a form option field I have a php page that has a web form on it. I do a query to populate the options in a drop down box in the form. [code] <select size="1" name="customer"> <?PHP while($query_data1=mysql_fetch_row($result1)){ echo"<option value='$query_data1[0]'>$query_data1[1]</option>"; } ?> [code] $query_data1[0] is a userID number $query_data1[1] is the user's Email address So when the user selects an email addres from the drop down box, the userID is stored and later writen to a database. What I now need to do is store not only the userID but the email address as well. Is there a way using a form to store 2 values using one drop down box? So basically I want to store the userID and the Email address to a variable in the form so that both may be written to different fields in the database later. Jeff -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I sometimes build the value of the list option like this: <option value="UserID~!~emailaddress">Email Address</option> Then use the split function (split("~!~", $var)) to get the two (or more) values without reliance on javascript. Daryl |
|
|||
|
Jeff, et al --
...and then Jeff McKeon said... % % I have a php page that has a web form on it. Yay! Yippee! That's great! Oh, that's not the substantive body of your note? :-) % % I do a query to populate the options in a drop down box in the form. % ... % So when the user selects an email addres from the drop down box, the % userID is stored and later writen to a database. Right. % % What I now need to do is store not only the userID but the email address OK. % as well. Is there a way using a form to store 2 values using one drop Well, yes and no. You can store only one value in a field, but that value can be anything you want it to be. % down box? So basically I want to store the userID and the Email address % to a variable in the form so that both may be written to different % fields in the database later. If I were going to do this (and I've done a bit like it), I would first make an array of everything to be sent, then serialize it, and finally base64_encode it and use that as the value. When you get it on the other side, just decode and then unserialize and you have your array back to use as you wish. This works for large numbers of vars as well as just a few. % % Jeff HTH & HAND :-D -- David T-G * There is too much animal courage in (play) davidtg@justpickone.org * society and not sufficient moral courage. (work) davidtgwork@justpickone.org -- Mary Baker Eddy, "Science and Health" http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (FreeBSD) iD8DBQE/s/qXGb7uCXufRwARAmd+AKCOTKgV8Zy7a+UpOo2NXZHIHbPKtACf baqR G/fnaBJT7gweC1FMNyMv/Vg= =69oJ -----END PGP SIGNATURE----- |