Posted by Kim Andrι Akerψ on 12/29/05 14:41
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>
--
Kim AndrΓ© AkerΓΈ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Navigation:
[Reply to this message]
|