# Drop Down Menu

**URL:** <https://www.phphelp.com/t/drop-down-menu/20856>\
**Category:** General PHP Help\
**Created:** [August 14, 2013, 10:30pm UTC](https://www.phphelp.com/t/drop-down-menu/20856 "2013-08-14T22:30:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![traydavid](https://www.phphelp.com/letter_avatar_proxy/v4/letter/t/a587f6/32.png) [@traydavid](https://www.phphelp.com/u/traydavid)\
**Post date:** [August 14, 2013, 10:30pm UTC](https://www.phphelp.com/t/drop-down-menu/20856/1 "2013-08-14T22:30:39Z")

</div>

This code creates one drop down menu for each item in the table. I’d like all the items in the table to be in one drop down menu. Seems like something simple in the html, but I can’t figure it out. Any help is appreciated. Thanks.

[php]\<?php

$query = “SELECT typeid, foodtype from intlfoodtype”;  
$result = mysql\_query($query);

echo “\<table class=“ex3” border=“0”\>\n”;  
while($row=mysql\_fetch\_array($result, MYSQL\_ASSOC))  
{  
$typeid = $row[‘typeid’];  
$foodtype = $row[‘foodtype’];

```
  echo "<tr><td width=\"100\">\n";
  echo "</td><td>\n";

  echo "<select>";
  echo '<option value="'.$typeid.'">'.$foodtype.'</option>';

  echo "</td><td>\n";
  echo "</td></tr>\n";

```

}  
echo “”;  
echo “\n”;

?\>[/php]

---

<div class="post-metadata">

**Author:** ![Topcoder](https://www.phphelp.com/user_avatar/www.phphelp.com/topcoder/32/4356_2.png) [@Topcoder](https://www.phphelp.com/u/Topcoder)\
**Post date:** [August 15, 2013, 12:34am UTC](https://www.phphelp.com/t/drop-down-menu/20856/2 "2013-08-15T00:34:22Z")

</div>

Give this a try…

[php]\<?php

$query = “SELECT typeid, foodtype from intlfoodtype”;  
$result = mysql\_query($query);

echo “\<table class=“ex3” border=“0”\>\n”;  
echo “

\<td width=“100”\>\n”;  
echo “\n”;  
echo “”;

while($row=mysql\_fetch\_array($result, MYSQL\_ASSOC))  
{  
$typeid = $row[‘typeid’];  
$foodtype = $row[‘foodtype’];

```
  echo '<option value="'.$typeid.'">'.$foodtype.'</option>';

```

}

```
echo "</select>";
echo "</td><td>\n";
echo "</td></tr>\n";
echo "</tr></table>\n";

```

?\>[/php]

---

<div class="post-metadata">

**Author:** ![traydavid](https://www.phphelp.com/letter_avatar_proxy/v4/letter/t/a587f6/32.png) [@traydavid](https://www.phphelp.com/u/traydavid)\
**Post date:** [August 15, 2013, 1:31am UTC](https://www.phphelp.com/t/drop-down-menu/20856/3 "2013-08-15T01:31:23Z")

</div>

It worked! Thank you! I appreciate it.

---

<div class="post-metadata">

**Author:** ![traydavid](https://www.phphelp.com/letter_avatar_proxy/v4/letter/t/a587f6/32.png) [@traydavid](https://www.phphelp.com/u/traydavid)\
**Post date:** [August 15, 2013, 2:04am UTC](https://www.phphelp.com/t/drop-down-menu/20856/4 "2013-08-15T02:04:58Z")

</div>

> [@Topcoder](#):
>
> Give this a try..
> 
> [php]\<?php
> 
> $query = “SELECT typeid, foodtype from intlfoodtype”;  
> $result = mysql\_query($query);
> 
> echo “\<table class="ex3" border="0"\>\n”;  
> echo “\<td width="100"\>\n”;  
> echo “\n”;  
> echo “”; while($row=mysql\_fetch\_array($result, MYSQL\_ASSOC)) { $typeid = $row[‘typeid’]; $foodtype = $row[‘foodtype’]; echo '\<option value="'.$typeid.'"\>'.$foodtype.'\</option\>'; } echo "\</select\>"; echo "\</td\>\<td\>\n"; echo "\</td\>\</tr\>\n"; echo "\</tr\>\</table\>\n"; ?\>[/php] I tried to add a hyperlink and that blew it. Any idea how to repair that? Thanks in any event. Here is the working PHP [php]echo ‘’.$name.‘’;[/php] And here is where I tried unsuccessfully to add the hyperlink: [php]echo "\<option value="‘.$catid.’"\>\<a href="index.php?content=buyproducts&cat=$catid"\>.$name.‘’;[/php]

---

<div class="post-metadata">

**Author:** ![Topcoder](https://www.phphelp.com/user_avatar/www.phphelp.com/topcoder/32/4356_2.png) [@Topcoder](https://www.phphelp.com/u/Topcoder)\
**Post date:** [August 15, 2013, 2:24am UTC](https://www.phphelp.com/t/drop-down-menu/20856/5 "2013-08-15T02:24:18Z")

</div>

You can’t have an anchor tag inside a dropdown. :’(

However you can add an onClick even like this…

[php]google[/php]

Which will accomplish the same thing

---

<div class="post-metadata">

**Author:** ![traydavid](https://www.phphelp.com/letter_avatar_proxy/v4/letter/t/a587f6/32.png) [@traydavid](https://www.phphelp.com/u/traydavid)\
**Post date:** [August 15, 2013, 2:32am UTC](https://www.phphelp.com/t/drop-down-menu/20856/6 "2013-08-15T02:32:17Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![traydavid](https://www.phphelp.com/letter_avatar_proxy/v4/letter/t/a587f6/32.png) [@traydavid](https://www.phphelp.com/u/traydavid)\
**Post date:** [August 15, 2013, 2:38am UTC](https://www.phphelp.com/t/drop-down-menu/20856/7 "2013-08-15T02:38:22Z")

</div>

Unfortunately this didn’t work either. I’m trying to loop through the catid numbers and link each one to the buyproducts page when selected from the dropdown. Thanks.

This does not work: [php]echo “\<option onClick=”‘index.php?content=buyproducts&cat=$catid’"\>’.$name.’’;[/php]
