Problems populating form select list dynamically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gyro
    New Member
    • Apr 2007
    • 2

    Problems populating form select list dynamically

    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_ob ject($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!
  • Gyro
    New Member
    • Apr 2007
    • 2

    #2
    Well I managed to solve it...

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

    Cool
    thanks for reading!!

    Comment

    Working...