Forum Moderators: coopster
So far in my database I have:
id, parent_id, cat_order, cat_name and visible.
And this is the little script I made to display them all:
function view_cat($cat_id)
{
$select_sql = "SELECT * FROM `categories` WHERE `parent_id` =$cat_id";
$resultlink = mysql_query($select_sql);
if ($members = mysql_fetch_array($resultlink)) {
do {
echo " -> $members[cat_name]";
view_cat($members[id]);
} while ($members = mysql_fetch_array($resultlink));
}
else
{
echo "<br>";
}
}
$select_sql = "SELECT * FROM `categories` WHERE `parent_id` =0";
$resultlink = mysql_query($select_sql);
if ($members = mysql_fetch_array($resultlink)) {
do {
echo "$members[cat_name]";
view_cat($members[id]);
} while ($members = mysql_fetch_array($resultlink));
}
else
{
echo "<center><b>No Categories found</b></center>";
}
This outputs the categories like:
Cat 1,0 -> Cat 1,1 -> Cat 1,2
Cat 2,0 -> Cat 2,1
But I cannot seem to get sub-categories working right, I want to output like this:
Cat 2,0 -> Cat 2,1 -> Cat 2,2
-------------> Cat 2,1
But Currently it only outputs like this:
Cat 2,0 -> Cat 2,1 -> Cat 2,2
-> Cat 2,1
Any ideas how I can get it display under the category but with the correct indent? Thanks for any help.