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

Problems populating form select list dynamically

Gyro
P: 2
Hi all, I'm a php newbie and have read various posts/articles on populating select lists dynamically from a db table. However, I cant seem to get it working in the way I want...

I have 3 select lists on a form and want to use a single piece of code to display each one by passing the relevant query to the code. My problem is that I dont know which mysql_fetch command to use because I cannot access each item by name only number (as the name will change depending on which table I use).

Which loop structure is best?

Currently I'm using...

$country_query = "select coutry_name from country";
$countrys = $conn->query($country_query);
$country_list = mysqli_fetch_object($countrys)

...

case "Country":
$select_list = $country_list;
break;

...

foreach ($select_list as $eachitem) {
?>
<option value="<?php echo $eachitem ?>"> etc.
<?php } ?>

...

Which only gives me one item in each of the select boxs!!! where r the others? How can I get all the countries listed?

Thanks in advance!
Apr 26 '07 #1
Share this Question
Share on Google+
1 Reply


Gyro
P: 2
Well I managed to solve it...

Used while ($eachitem = mysqli_fetch_array($select_field)) where $select_field is equated to the query result! then accessing $eachitem[0] gives me the values I want.

Cool
thanks for reading!!
Apr 26 '07 #2

Post your reply

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