Jump to content

Category Menu


risingfree

Recommended Posts

Hi,

Ok, I'm addicted and looking for some help  ;)

 

I've been trying all day to get something working, couple of things that go a bit beyond what I already know.

 

First thing is a category menu in a form, so that a category can be chosen. I can do that but I need to display these hierarchicaly.

 

This is what I have

Table fields - CatID, CatName, CatParent,

 

Query

mysql_select_db($database_members, $members);
$query_Recordset1 = "SELECT * FROM bus_categories ORDER BY CatName ASC";
$Recordset1 = mysql_query($query_Recordset1, $members) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

 

Display

<select name="CatID">
        <?php 
do {  
?>
        <option value="<?php echo $row_Recordset1['CatID']?>" <?php if (!(strcmp($row_Recordset1['CatID'], $row_Recordset1['CatID']))) {echo "SELECTED";} ?>><?php echo $row_Recordset1['CatName']?></option>
        <?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
?>
      </select>

 

That all works fine to display all the categories and the form works displaying like: arts & crafts

However, because some categories are repeated I need to display this like:

Angus - Arbroath - arts & crafts

 

Can anyone help me with this? I know I need to do a recursive query and I've been looking at a lot of examples but I'm just confusing myself.

 

Any help would be greatly appreciated.

 

Link to comment
https://forums.phpfreaks.com/topic/146511-category-menu/
Share on other sites

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.