View Full Version : Help Again
MustafaHepekiz
09-11-2002, 09:31 AM
Hi there!
I need help about a dropdown menu...
I want to take 2 values from an option function like;
<option value=1>This is One>
I want to take another value from this selection... How can i do? I use this as PHP it get values from MySQL to <option> but i can use only one value yo write MySQL again... I want take another one from one field! Help mee.....
Mustafa Hepekiz
www.gtechnics.comwww.gtechnics.com (http://www.gtechnics.com) :confused:
If I understand you correctly...
You're looking for a symbol seperated value pair that can then be re-read after submission
<option value="value1,value2">top two values</option>
echo '<select name="passtwovalues">
<option value="">select option below</option>';
while($res = mysql_fetch_row($result)) {
echo '<option value="'.$res['fieldone'].','.$res['fieldtwo'].'">$res['fieldthree'].'</option>';
}
echo '</select>';
then
if($_POST['passtwovalues']) {
$mytwovalues = explode(',',$_POST['passtwovalues'];
}
which would yield
$mytwovalues[0] = the chosen $res['fieldone'];
$mytwovalues[1] = the chosen $res['fieldtwo'];
Notes: If you use commas in the values, you would need to assign a different delimiter ... $res['1'].'_'.$res['2'] - explode('_'.... sort of thing. Also note - depending on your php build (I noted you offer quite a nice setup from your site), you may want if($HTTP_POST_VARS['passtwovalues']); or whatever.
Basically you are writing two variables as one, sending them as one and then ripping them apart again to make two.
As a subnote: useful functions for doing that sort of thing are
implode() (http://www.php.net/manual/en/function.implode.php)
explode() (http://www.php.net/manual/en/function.explode.php)
split() (http://www.php.net/manual/en/function.split.php)
and maybe
serialize() (http://www.php.net/manual/en/function.serialize.php)
unserialize() (http://www.php.net/manual/en/function.unserialize.php)
RadarBob
09-11-2002, 01:38 PM
Why not make it a <select multiple...>. What am I missing here?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.