|
Posted by J.O. Aho on 01/02/06 16:34
Kim André Akerø wrote:
> powerx wrote:
>
>> Hi All,
>>
>> Would have thought this was a FAQ but I'm having trouble googling it
>> so any help appreciated...
>>
>> I have an SQL database
>>
>> ID BRAND
>> 1 Apples
>> 2 Pears
>> 3 Oranges
>> 4 ...
>> 5 ...
>>
>> What is the easiest way of getting the SQL "Brand List" into a
>> dropdown menu in my HTML / PHP page. It should automatically update
>> when new items are added?
>
> Assuming you mean MySQL, here's a simple example (HTML 4 used for
> simplicity's sake):
>
> <select name="fruit"><?php
> $results = mysql_query("SELECT id,brand FROM fruit_table");
> while ($row = mysql_fetch_assoc($results)) {
> echo "<option value=".$row['id'].">".$row['brand'];
> }
> ?></select>
>
That generates quite sloppy HTML4
<select name="fruit"><?php
$results = mysql_query("SELECT id,brand FROM fruit_table");
while ($row = mysql_fetch_assoc($results)) {
echo "<option value=\"".$row['id']."\">".$row['brand']."</option>";
}
?></select>
Navigation:
[Reply to this message]
|