|
其实就是利用里面的star方法和show方法在循环。但是发现ci里面的模型不能直接这样用?
以前是用while($row = mysql_fetch_array($res))作循环的,
但是现在用while ($row = $res->row_array()) 好像无效。怎么办呢?
PHP复制代码
$tree = new tree ();
$a = $tree->star();
print_r($a);
class tree {
function star ()
{
$this->db = $conn;
$sql = "select * from tvmenu where bid=0";
$this->res = mysql_query($sql, $this->db);
$this->arr = array();
$this->show($this->res,1,0);
return $this->arr;
}
function show ($res,$i,$ii){
while($row = mysql_fetch_array($res))
{
$sql = "select * from tvmenu where bid=$row[id]";
$res_sub = mysql_query($sql, $this->db);
$num_sub = mysql_num_rows($res_sub);
if($num_sub > 0)
{
$array=array();
echo "<li>+,{$row['id']},{$row['name']},{$i},{$ii}</li>";
$array['id'] = $row['id'];
$array['name'] = $row['name'];
$array['exp'] = 'Y';
$array['layer'] = $i;
array_push ($this->arr, $array);
$i++;
$this->show($res_sub,$i,$ii);
$i--;
}else{
$array=array();
echo "<li>-,{$row['id']},{$row['name']},{$i},{$ii}</li>";
$array['id'] = $row['id'];
$array['name'] = $row['name'];
$array['exp'] = 'N';
$array['layer'] = $i;
array_push ($this->arr, $array);
}
}
}
}
复制代码 |
|