homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Pull Down Menu That Corresponds to MySQL Database

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

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)

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)

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)

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)

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)

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]

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved