By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,892 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,892 IT Pros & Developers. It's quick & easy.

database values in the combo box

P: 4
its easy to place an array values in the combo box.
but i need to know how can i do it if i have to retrieve the values from a database.
my platform is PHP MySql. please i need help :(
combo box name=dep_list_selected
database name = dependency.
if i choose value 'A' then the corresponding values of it that are stored in the table should appear in the combo box.
if i choose another option then its respective values should be displayed.
Mar 1 '07 #1
Share this Question
Share on Google+
1 Reply


P: 2
its easy to place an array values in the combo box.
but i need to know how can i do it if i have to retrieve the values from a database.
my platform is PHP MySql. please i need help :(
combo box name=dep_list_selected
database name = dependency.
if i choose value 'A' then the corresponding values of it that are stored in the table should appear in the combo box.
if i choose another option then its respective values should be displayed.

So you can see it :
Name:
</td>
<?php

$query = "select last_name,first_name
from student
order by first_name ";
$search_stu=mysql_query($query)or die(mysql_error());
$name = array();

//last name into array
while ($rowN = mysql_fetch_assoc($search_stu))
{
array_push($name, $rowN["last_name"]);

}
?>
<?php //list of name ?>
<td>
<select name="name">
<option value=" "></option>

<?php foreach($name as $valueN) { ?>
<option value="<?= $valueN ?>" <? if ($HTTP_POST_VARS['last_name'] == $valueN){ echo "SELECTED";}?>><?= $valueN ?></option>
<? }

?>
Mar 1 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.