Hi!
Currently I'm using a tree like sections structure, e.g.
Table: sections
+--------+------------+----------+
| sec_id | sec_parent | sec_name |
+--------+------------+----------+
| 1 | 1 | Home |
| 2 | 1 | News |
| 3 | 2 | Sports |
| 4 | 3 | Soccer |
| 5 | 4 | Teams |
| 6 | 5 | Arsenal |
| 7 | 1 | World |
| 8 | 7 | England |
| 9 | 8 | Economy |
+--------+------------+----------+
Also I'm using the function below to cover the tree:
function cover_tree(){
$query = "select * from sections";
$result = mysql_query($query);
$i=1;
while($row = mysql_fetch_array($result)){
$sec_id[$i] = $row['sec_id'];
$sec_parent[$i] = $row['sec_parent'];
$sec_name[$i] = $row['sec_name'];
while($sec_parent[$i] > 1) {
$query = "select * FROM sections where sec_id = $sec_parent[$i]";
$subresult = mysql_query($query);
$subrow = mysql_fetch_array($subresult);
$subsec_parent[$i] = $subrow['sec_parent'];
$subsec_name = $subrow['sec_name'];
$sec_name[$i] = $subsec_name." > ".$sec_name[$i];
}
$i++;
}
if($sec_name){
for(reset($sec_name); $key=key($sec_name); next($sec_name)) {
$sections_tree[$sec_id[$key]] = $sec_name[$key];
}
}
return $sections_tree;
}
The above function will return:
Home
News
News > Sports
News > Sports > Soccer
News > Sports > Soccer > Teams
News > Sports > Soccer > Teams > Arsenal
World
World > England
World > England
World > England > Economy
I would like to see only subsections below the section Sports, (sec_id = 3), thus my sections_tree should be represented,
Sports
Sports > Soccer
Sports > Soccer > Teams
Sports > Soccer > Teams > Arsenal
The question is:
How could I improve this function to show only subsections below a pre-determined section???
Any ideas!?!?
Kindest Regards,
marcoBR
BTW, sorry 4 my english ...