PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi. I would like to know how can I select an existing drop down list from a form and populate it with the records from a database. I have written the code, but i do not know how to select the existing drop down list. It always creates a new one. This is the code I am using:
Hi. The list gets populated, but the program creates a new one, it is not using the one which already exists on the form. So the original one is still empty. Thank you.
<select name = "lstBuildings" id="lstBuildings">
<option value="1">hello</option>
<option value="2">bye</option>
</select>
<?php
// and then try populate it with more information here:
$str_sql = "SELECT ......";
$result = mysql_query($str_sql) or ($slq_str . mysql_error());
echo " <select name = \"lstBuildings\" id=\"lstBuildings\">";
while ($row = mysql_fetch_array($result)){
echo "<option value = $row[field]>$row[field]</option>";
}
echo "</select>";
}
?>
if this is the case, the first one is being overwritten. rather use:
Hi. Yes. Once when defining the form for input, and once when trying to populate it. The code for populating the list is in a different file however, but this should not be a problem, the action gets executed on the same page. If I am going to use the name only once, how can I place it into a specific cell of the table on the form? Thank you!
Well that would not work, as soon as you use the <select name...> etc, it'll create a new one, or overwrite the existing one. Well if it's on two different pages, store the options in a variable, and echo it later? like this:
Hi. I think its the same thing. It will still create a new list. Because the original list already exists. I forgot to mention that the list should get populated when I click a radio button. So my intention is not to create a new list, but to populate an existing one. Thank you.