-3

Say I've got a dropdown list on my site like this:

<select>
<option value="test">Volvo</option>
<option value="icles">Saab</option>
<option value="lol">Mercedes</option>
<option value="hax">Audi</option>
</select> 

But I don't want the above values, what if I want to get the values from an SQL table, how would I do this? Obviously this would be PHP but could someone give me an example?

1 Answers1

2

you will have to do it like this:

first select the values:

$result = "SELECT * from table";

then you will have to foreach() those values and create your selectbox like this:

echo '<select>';
foreach($result as $res) {
   echo '<option value="'.$res['somevalue'].'">' . $res['car_name'] . '</option>';
}
echo '</select>';

and you're done :D

Ares Draguna
  • 1,641
  • 2
  • 16
  • 32