table('dept_category')." order&"/> table('dept_category')." order&">
Home > Article > Backend Development > 何位看下这个循环嵌套数组有误吗
哪位看下这个循环嵌套数组有误吗?
function get_number_list($cat_id)<br />{<br /> $sql=$GLOBALS['db']->query("select * from ".$GLOBALS['db']->table('dept_category')." order by sort");<br /> while($row=$GLOBALS['db']->fetch_array($sql)){<br /> if($row){<br /> $result=$GLOBALS['db']->query("select * from ".$GLOBALS['db']->table('number')." where dept=".$row['cat_id']." and cat_id='$cat_id' order by sort");<br /> while($rows=$GLOBALS['db']->fetch_array($result)){<br /> if($rows){<br /> $number_show[] = array(<br /> 'id' => $rows['id'],<br /> 'title' => $rows['title'],<br /> 'user' => $rows['username']<br /> );<br /> }<br /> }<br /> $cat_name[]=array(<br /> 'sort' => $row['sort'],<br /> 'cat_name' => $row['cat_name'],<br /> 'topid' => $number_show<br /> );<br /> }<br /> }<br /> return $cat_name;<br /> }
<table width="99%" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"><br /> {foreach from=$dept_list name=dept_list item=dept}<br /> <tr bgcolor="#FFFFFF"><br /> <td style="max-width:90%" colspan="2" class="bumen"> {$dept.cat_name}</td><br /> </tr><br /> {foreach from=$dept.topid item=number}<br /> <tr bgcolor="#FFFFFF"><br /> <td width="46%" height="25" align="center">{$number.user}</td><br /> <td width="54%" align="center">{$number.title}</td><br /> </tr><br /> {/foreach}<br /> {/foreach}<br /> </table>
function get_number_list($cat_id)<br />{<br /> $sql=$GLOBALS['db']->query("select * from ".$GLOBALS['db']->table('dept_category')." order by sort");<br /> while($row=$GLOBALS['db']->fetch_array($sql)){<br /> if($row){<br /> $result=$GLOBALS['db']->query("select * from ".$GLOBALS['db']->table('number')." where dept=".$row['cat_id']." and cat_id='$cat_id' order by sort");<br /> while($rows=$GLOBALS['db']->fetch_array($result)){<br /> if($rows){<br /> $number_show[] = array(<br /> 'id' => $rows['id'],<br /> 'title' => $rows['title'],<br /> 'user' => $rows['username']<br /> );<br /> }<br /> }<br /> $cat_name[]=array(<br /> 'sort' => $row['sort'],<br /> 'cat_name' => $row['cat_name'],<br /> 'topid' => $number_show<br /> );<br /> unset($number_show);<br /> }<br /> }<br /> return $cat_name;<br /> unset($cat_name);<br /> }利用unset对数组进行清空。