Ask how to read an unlimited class
is a simple infinite class classification.
The categorytable structure is as follows:
ID name PID
Now you need to read all the classifications into array () or JSON format
Little brother on the internet to find a lot of things to see but not very familiar with PHP a lot of can not be used
Like $db->fetch_array (), $db->fetch_array () These are mistakes.
Now, ask the great God for a simple and practical look, thank you, my little brother.
To the younger brother to use is the frame of CodeIgniter first thank you big God! ~
------Solution--------------------
function Getcat ($pid, $lnum =1, $str = ", $level =0) {
Static $catlist =array ();
$sql = "SELECT * categorytable where pid= $pid";
$rst = mysql_query ($sql);
while ($row =mysql_fetch_assoc ($rst)) {
$l = Str_repeat (" ", $level * $lnum);
$catname = $l. ($pid ==0? ': $str). $row [' Cat_name '];
$catlist []=array (' catid ' = $row [' cat_id '),
' CatName ' = $catname
);
Getcat ($row [' cat_id '], $lnum, $STR, $level + 1);
}
return $catlist;
}
------Solution--------------------
http://bbs.csdn.net/topics/390364669