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

 

<?
$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).

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.