Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Pull Down Menu That Corresponds to MySQL Database



2:43 am on May 8, 2008 (gmt 0)

5+ Year Member

I need to make some sort of pull down menu, probably done in html, that forms it's list from a MySQL database. I am assuming this would be done with PHP tags but I have no clue how.

Thanks in advance!


12:16 pm on May 8, 2008 (gmt 0)

5+ Year Member

PHP has inbuilt functions called mysql_list_tables and mysql_list_fields that you can use to assemble the dropdowns.


12:25 pm on May 8, 2008 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

the basics are you grab the data from your mysql database and then loop through them using mysql_fetch_array or a similar function.

Then as you loop through you can output your values from your database and your html together

this is a good place to start
Basics of extracting data from MySQL using PHP [webmasterworld.com]

Sarah Atkinson

3:33 pm on May 8, 2008 (gmt 0)

10+ Year Member

I just did one of these this week. Basicly you do what Jatar said:
here's my code:

include "db.inc.php";
$sql = "SELECT DISTINCT Make FROM table ";
exit('<p>Error with Query...Error:' . mysql_error() . '</p>');
echo "<li><a href=\"http://www.yoursite.com/yourpage.php?Make=" . $Make . "\" class=\"class\">". $Make. "</a>\n";
echo '<ul>';
$sql2 = "SELECT DISTINCT Model FROM table WHERE Make='$Make'";
exit('<p>Error with Query...Error:' . mysql_error() . '</p>');
echo "<li><a href=\"http://www.yoursite.com/yourpage.php?MakeModel=". $Make . '-' . $Model. "\">$Model</a></li>\n";
echo "</ul></li>";

I replaced some of the identifying variables but I think you can get the idea. It populates a list of "makes" in stock and gives each one a sublist of their models.

[edited by: jatar_k at 6:29 pm (utc) on May 8, 2008]
[edit reason] added some line breaks [/edit]

Sarah Atkinson

3:35 pm on May 8, 2008 (gmt 0)

10+ Year Member

oh and to make it pull down I used a Pop-menu using css and lists. This gave me greater control on looks
then just a regular jump menu would


4:06 pm on May 8, 2008 (gmt 0)

5+ Year Member

That is a little bit to much for me to understand... Do you think you could post the entire page so I could understand what things did? Like $sql2 what is that?

And, I am not really sure how the CSS would go... maybe you could post your css as well?

[edited by: Spiceydog at 4:06 pm (utc) on May 8, 2008]


Featured Threads

Hot Threads This Week

Hot Threads This Month