Hi all. I have been working on this script all day now with no headway what so ever. I have found about 10 ways how NOT to make this script work. Anyways what I am trying to do is create an online store for a client. I am attempting to build the category section right now, and I am trying to create a dropdown menu that shows off all the categories and their sub categories. The problem i am having is getting all the categories show up, The way the shop is going to be setup is so that you are allowed unlimited sub catagories, meaning a category can have a huge number of parents above it. Let me try to show what I am looking for in terms on a the dropdown menu
Sporting Good
-Fishing
--Fly Fishing
--Stream Fishing
--Crossbow Fishing
--Ocean Fishing
---Shark Fishing
-Football
--Clothing
---Helmets
---Pads
----Used Pads
--Balls
---Big Skin
---Cow Skin
That should give a good idea, now if i only had 4 levels of categories it would not be all that hard, however there could be 10 or even more levels. I am going to post my code here, It does not work the way i need it to at all but i want to show atleast my last attempt at trying to get this to work.
<?php
include 'config.inc.php';
include 'connect.php';
$x = 0;
$sql_statement[$x] = mysql_query("SELECT * FROM categories_link WHERE parent_id = 0");
while($row[$x] = mysql_fetch_array($sql_statement[$x]))
{
$id = $row[$x]['id'];
echo "<option value=".$row[$x]['id'].">".$row[$x]['name']."</option>";
if(!isset($runs[$x]))
{
$runs[$x] = 0;
}
$runs[$x] ++;
$sql_temp = mysql_query("SELECT * FROM categories_link WHERE parent_id = '$id'");
$return = mysql_num_rows($sql_temp);
if($return != 0)
{
$x++;
$returns[$x] = $return;
$sql_statement[$x] = mysql_query("SELECT * FROM categories_link WHERE parent_id = '$id'");
}
else if ($x != 0)
{
if($returns[$x] == $runs[$x])
{
$x --;
}
}
}
?>
Any help would be awesome, I cannot believe something like this is giving me such a hard time, i am not sure if I am just not seeing the simple picture or what. Thanks for any help.