Jump to content

How to do a mysql Database driven menu dropdown


fatcat2010

Recommended Posts

i experts:

I created a departments table and populated value as follows

SELECT department_id , name,description FROM departments

...the table has

Trading department

Food department

Toy departments

However, I don't know how to create a dropdown in the website frontend like this format: ( Mouse over or click "Departments" navigation menu button will trigger a dropdown with list of department names in above mysql "Departments" table. (do i need a javascript to pull out department name from mysql table or sth else?

 

Home Department About Us

  • Trading department
    Food department
    Toy departments

 

Link to comment
Share on other sites

<?
$sql = mysql_query("SELECT * FROM
departments
ORDER BY name
DESC");
//mysql database driven select menu sorted alphabetically by name

//name form field
echo "<select name=\"formfieldname\">\n";
echo "<option value=\"NULL\">Please Select</option>\n";

while($row = mysql_fetch_array($sql)){
//insert value
echo "<option value=\"".stripslashes($row[department_id])."\">";
//insert display name
echo stripslashes($row[name])."</option>\n";
}
echo "</select>\n";

?>

 

In all fairness, I learned this method by a book written by a phpfreaks member or owner (I just remember seeing this website mentioned in the book).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.