I have a database where the categories are stored in one field like this:
category1/category2/category3
The same subcategories are used under different categories like this:
a/b/c/d
a/n/c/d
z/n/c/d
z/c/d
Sometimes there are 2 subcategories and sometimes there are 3 subcategories:
a/b/c/d
a/b/c
I'm trying to figure out how to make a store out of this. So basically I would like to show the category and then the subcategories below each category without showing the same category multiple times.
So I need to get all the unique subcategories for each category. So using the examples above I would want to display A as a category with b,c,d,n as subcategories, and then Z as a category with c,d,n as subcategories below it.
Here's what I have so far but I programmed it incorrectly and I'm not sure how get it to do what I want:
$query2="SELECT DISTINCTROW(category) FROM datafeed";
$result2=mysql_query($query2);
$count=0;
while($row2=mysql_fetch_assoc($result2)) {
extract($row2);
$breadcrumb=explode("/",$category);
$breadcrumb1[$count]=$breadcrumb[0];
$breadcrumb2[$count]=$breadcrumb[1];
$breadcrumb3[$count]=$breadcrumb[2];
$breadcrumb4[$count]=$breadcrumb[3];
$count++;
}
$breadcrumb1=array_filter($breadcrumb1);
$breadcrumb1=array_unique($breadcrumb1);
$breadcrumb2=array_filter($breadcrumb2);
$breadcrumb2=array_unique($breadcrumb2);
$breadcrumb3=array_filter($breadcrumb3);
$breadcrumb3=array_unique($breadcrumb3);
$breadcrumb4=array_filter($breadcrumb4);
$breadcrumb4=array_unique($breadcrumb4);
$count=0;
foreach ($breadcrumb1 as $value) {
echo "<h6 align=center><a href=\"\">".$value."</a></h6>";
$count2=0;
foreach ($breadcrumb2 as $value2) {
echo "<a href=\"\">".$value2."</a><BR>";
$count2++;
}
$count++;
}