Hey guys,
I have weird problem,
Somewhere in my DB I have a table that had items like this:
id | Name | Sub_of
1 | A | 0
2 | B | 1
3 | C | 1
4 | D | 2
5 | E | 2
All I am trying to do is automatically generate a table so that I can see all the sub_of like this (A,B,C... are table headers I will be writing the table row by row. e.g. <tr>...</tr> ):
I have tried to get the depth of the final table header and the number of final set of columns like this :Code:|------------------------------------| |----------------A-------------------| -------------------------------------- |-----------B---------- |------C-----| -------------------------------------- |----D--| ----- E ------|------------| -------------------------------------- |--------| --------------|------------| |--------| --------------|------------| |--------| --------------|------------| ...
I hope this makes sense about what I am looking for. Please help.Code:function tree_span($category_id,$find) { $q = "SELECT category_id, name, id from ".$table_prefix."categories where sub_of = ".$category_id." order by name"; $query = mysql_query($q); if (!$query) echo "Database Error : ".$q; else { $depth = mysql_num_rows($query); if($depth !=0) { $category_depth = $category_depth+1; } while ($row=mysql_fetch_row($query)) { if ($row[0] != $id) { $category_span = $category_span +1; tree_span($row[0],$find); } } }



Reply With Quote


Bookmarks