What is the bitwise? is this nested loop array incorrect?

Source: Internet
Author: User
Which one can check whether this nested loop array is incorrect? Function & nbsp; get_number_list ($ cat_id) {& nbsp; $ SQL $ GLOBALS [db]-& gt; query (select & nbsp; * & nbsp; from & nbsp ;. $ GLOBALS [db]-& gt; table (dept_category ). & nbsp; order & which one should check whether this nested loop array is incorrect?
function get_number_list($cat_id)
{
$sql=$GLOBALS['db']->query("select * from ".$GLOBALS['db']->table('dept_category')." order by sort");
while($row=$GLOBALS['db']->fetch_array($sql)){
if($row){
$result=$GLOBALS['db']->query("select * from ".$GLOBALS['db']->table('number')." where dept=".$row['cat_id']." and cat_id='$cat_id' order by sort");
while($rows=$GLOBALS['db']->fetch_array($result)){
if($rows){
$number_show[] = array(
'id' => $rows['id'],
'title' => $rows['title'],
'user' => $rows['username']
);
}
}
$cat_name[]=array(
'sort' => $row['sort'],
'cat_name' => $row['cat_name'],
'topid' => $number_show
);
}
}
return $cat_name;
}

This is the source code, and this is:
This is the static page code:












{foreach from=$dept_list name=dept_list item=dept} {foreach from=$dept.topid item=number} {/foreach} {/foreach}
 {$dept.cat_name}
{$number.user} {$number.title}

------ Solution --------------------
Because number_show is not cleared and the first record is obtained, it will be available later.
------ Solution --------------------
function get_number_list($cat_id)
{
$sql=$GLOBALS['db']->query("select * from ".$GLOBALS['db']->table('dept_category')." order by sort");
while($row=$GLOBALS['db']->fetch_array($sql)){
if($row){
$result=$GLOBALS['db']->query("select * from ".$GLOBALS['db']->table('number')." where dept=".$row['cat_id']." and cat_id='$cat_id' order by sort");
while($rows=$GLOBALS['db']->fetch_array($result)){
if($rows){
$number_show[] = array(
'id' => $rows['id'],
'title' => $rows['title'],
'user' => $rows['username']
);
}
}
$cat_name[]=array(
'sort' => $row['sort'],
'cat_name' => $row['cat_name'],
'topid' => $number_show
);
unset($number_show);
}
}
return $cat_name;
unset($cat_name);
}
Use unset to clear the array.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.