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