Log in

View Full Version : create a menu



abhikerl
06-17-2008, 08:00 AM
Hi, I hope anyone can help me out. I need to create a menu as the the syntax below.

Category (HUMAN)
subCategory1 (Man)
subcategory2 (Girl)
... .... ... ....

Category2 (FRUITS)
subCategory1 (Mango)
subCategory2 (Apple)
... ....

I am not using any javascript code, only php and database which is storing the details. I'll be very grateful if you can help me out. I spend too much time trying to do that. thanks in advance

Nile
06-18-2008, 03:22 AM
My idea failed, sorry.

Jas
06-20-2008, 06:27 PM
What does the table look like?

To make the menus nicer than plain HTML, you might also consider having PHP produce Javascript to produce dropdown menus.

EDIT: Try something like this:


$rows = MySQL_Query("SELECT DISTINCT catagory FROM `mypages` ");
while($row = MySQL_Fetch_Array($rows)){
$contents .= '<div>Catagory ('.$row['catagory'].')</div>';
$rows2 = MySQL_Query("SELECT subcatagory FROM `mypages` WHERE catagory = \"".$row['catagory']."\"");
while($row2 = MySQL_Fetch_Array($rows2)){
$contents .= '<div>Subcatagory ('.$row2['subcatagory'].')</div>';
}
}
print $contents;


If your table is like this:


catagory | subcatagory
--------------------------
Cat 1 | subcat 1
Cat 1 | Subcat 2
Cat 2 | subcat A
Cat 2 | subcat B

The output will look like:

Catagory (Cat 1)
Subcatagory (subcat 1)
Subcatagory (subcat 2)
Catagory (Cat 2)
Subcatagory (subcat A)
Subcatagory (subcat B)