Jump to content

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>";
.
.
.
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.