-2

Possible Duplicate:
Populate a Drop down box from a mySQL table in PHP

I'm new to PHP/mySQL, but I'm learning it. I'm just creating a simple script to learn about mySQL, retrieving data from the database etc. I'm stuck on something, I hope you guys can help me!

I want to show the data of table 'leerlingen' in a html form, in the 'select' html tag. Each value has to has its own option tag, so like this:

  <select>
    <option value="VALUE 1">VALUE 1</option>
    <option value="VALUE 2">VALUE 2</option>
    <option value="VALUE 3">VALUE 3</option>
    <option value="VALUE 4">VALUE 4</option>
  </select>

I've searched a lot at Google, tried many things, but nothing seems to work..

Thanks!

Jelle

Community
  • 1
  • 1
Jellevdschoot
  • 27
  • 2
  • 10
  • Doing the following google search "php mysql select" yielded an example in the first result for doing what you want: https://www.google.com/search?q=php+mysql+select&aq=f&oq=php+mysql+select&aqs=chrome.0.57j5j60j0l2j62.5620&sugexp=chrome,mod=0&sourceid=chrome&ie=UTF-8 – Kenneth Dec 13 '12 at 14:07

1 Answers1

3

It would appear you need to write a foreach loop to parse through each database row you have from your query. Example below (result as an multidimensional array):

<select>
<?php
    foreach($rowset as $row) {
        echo '<option value="'.$row['id'].'">'.$row['value'].'</option>';
    }
?>
</select>
Carl Owens
  • 1,292
  • 8
  • 14
  • There's just one problem now: the data isn't inserted to the table in the database.. The other fields are inserted, so that part of the code is allright I guess.. – Jellevdschoot Dec 13 '12 at 14:56