Jump to content

[SOLVED] multipe dynamic select box


project3

Recommended Posts

Hi,

 

What I need to do is have like 25 identical drop down boxes besides the name of the box.

I know how to fill it from the database.

but only if i do 25 mysql statements.

 

so what i would like to do is fill the <options></options> values only once.

 

Then I want to use that data inbetween the select boxes with different names.

 

is there a way to do that or do i need to have multiple sql statements.

 

Thanks in advance!

 

Link to comment
https://forums.phpfreaks.com/topic/86568-solved-multipe-dynamic-select-box/
Share on other sites

The OP stated he wanted 25 identical slect boxes. This is very simple, just create the select options once - but instead of echo'ing them to the page, add them to a variable. Then you can add the options to as many select lists as you want. Also, if you need to pre-select the default option for each independantly, then just create a function using the result set from the query:

 

<?php

$query = "SELECT label, value FROM table";
$results = mysql_query($query);
while ($option = mysql_fetch_assoc($results)) {
  $optionList .= "<option value = \"{$option['value']}\">{$option['label']}</option>\n";
}

echo "<select name=\"option1\">$optionList</select>";
echo "<select name=\"option2\">$optionList</select>";
echo "<select name=\"option3\">$optionList</select>";
.
.
.
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.