|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
php5 - Displaying hierarchical data as tree
I have the following query to my categories table:
SELECT l1.id as lev1_id,l2.id as lev2_id,l3.id as lev3_id,l1.category AS lev1, l2.category as lev2, l3.category as lev3 FROM categories AS l1 LEFT JOIN categories AS l2 ON l2.parentCat = l1.id LEFT JOIN categories AS l3 ON l3.parentCat = l2.id WHERE l1.parentCat = NULL Which outputs something like: ------------------------------------------------------- lev1_id | lev2_id | lev3_id |lev1 | lev2 | lev3 | ------------------------------------------------------ 1 | 4 | 7 |makeup | lipstick | wet look 1 | 4 | 8 |makeup | lipstick |matt 1 | 5 | 9 |makeup | mascara| black 2 | 11 | NULL|skincare|creame | NULL 3 | 12 | 13 |haircare |hairspray| Xtra Hold I want to be able to display this data as a tree with 3 levels. I know a foreach os a good place to start but dont know what after that. Any help would be much appreciated. |
|
#2
|
|||
|
|||
|
I'm not quite sure what you mean, but you can display the variables anyway you wish.
I imagine you have a nested array in your main array of data... So each row = its own array... If thats the case then this would work (to display the variables). Code:
$count = count($array);
for($i=0; $i<$count; $i++){
$icount = count($array[$i]);
for($x=0; $x<$icount; $x++){
echo $array[$i][$x] ." | ";
}
echo "<br />";
}
__________________
- Richie |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > php5 - Displaying hierarchical data as tree |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|