Re: multiple choice dropdown box puzzle
| From: | Curtis Maurand | Date: | Mon, 23 Feb 2009 16:57:27 +0000 |
| Subject: | Re: multiple choice dropdown box puzzle | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-288686@lists.php.net to get a copy of this message | ||
You're looking for something like:
This gets called 10 times from another function, but this is sort of what you're looking for. This gives me a combo-box.
function qselect($mysql_link, $i)
{
$driverquery = "select car_no, drv_name from cars order by car_no + 0";
$driverresult = mysql_query($driverquery, $mysql_link);
print(" <select name='pick$i'>\n");
while ($driverrows = mysql_fetch_array($driverresult))
{
print(" <option value = '$driverrows[0]'>$driverrows[1]</option>\n");
}
print(" </select>\n");
}
HTH
Curtis
Afan Pasalic wrote:
PJ wrote:I think this is a tough one... and way above my head: PLEASE READ ALL OF THE ABOVE TO UNDERSTAND WHAT I AM TRYING TO DO. Having a bit of a rough time figuring out how to formulate php-mysql to insert data into fields using a multiple dropdown box in a form. to post I am using the following: snip...first, I think, $categoriesIN is string, but in the form you made it as an array $categoriesIN[]. I think you have to "modify it a little bit, something like {$categoriesIN}.'[]' second, I think the php part "FOR ( $ii = 0 ; $ii < count($categoriesIN) ; $ii++ )" can't be part of the mysql statement, it should be "outside" the statement FOR ( $ii = 0 ; $ii < count($categoriesIN) ; $ii++ ) {$categoriesIN = $_POST["categoriesIN"];...snip... <select name="$categoriesIN[]" multiple="multiple"><OPTION>Choose Categories...</option> <OPTION VALUE="<? echo $categoriesIN; ?>">1 <OPTION VALUE="<? echo $categoriesIN; ?>">2 <OPTION VALUE="<? echo $categoriesIN; ?>">3 <OPTION VALUE="<? echo $categoriesIN; ?>">4 <OPTION VALUE="<? echo $categoriesIN; ?>">5 </SELECT>...snip... $sql4 = "FOR ( $ii = 0 ; $ii < count($categoriesIN) ; $ii++ )INSERT INTO temp (example) $categoriesIN[$ii]" ; $result4 = mysql_query($sql4, $db); ...snipthis does not work! The other posts work like a charm... but this... I cannot figure out what I should be entering where... I have tried several different configurations, but nothing seems to work... I found this as a model for entering the selections but can't figure out how to modify it for my needs: <select name="branch_no[]" multiple="multiple" size="5"> <option > Choose your location(s) </option> <option value="3100">3100</option> <option value="3105">3105</option> <option value="3503"> 3503</option> <option value="3504"> 3504</option> </select> What I would like to do is something like the following: <select name="$categoriesIN[]" multiple="multiple"><OPTION>Choose Categories...</option> <OPTION VALUE="1">History <OPTION VALUE="2">Temples <OPTION VALUE="2">Pharaohs and Queens <OPTION VALUE="4">Cleopatra <OPTION VALUE="4">Mummies </SELECT> and going further, I would like to be able to use a table that actually holds these values to feed them to the code above. I am sure this is possible but it must take some huge knowledge and experience to do it.BUT ... as I look at things, I am wondering if the FOR statement in the above should be used to do several INSERTs, that is, one $sql(number) per selected category... now, would that require many $sqls or many INSERTs within the $sql ?$sql4 = "INSERT INTO temp (example) $categoriesIN[$ii]" ; $result4 = mysql_query($sql4, $db); }afan