You are here: Re: SQL driven Menus in PHP « All PHP « IT news, forums, messages
Re: SQL driven Menus in PHP

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация