Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

这里有BUG,有可能导致死循环 #3

Open
diamont1001 opened this issue Feb 18, 2021 · 0 comments
Open

这里有BUG,有可能导致死循环 #3

diamont1001 opened this issue Feb 18, 2021 · 0 comments

Comments

@diamont1001
Copy link

function get_parent_cats($cat)

$arr = $GLOBALS['db']->GetAll('SELECT cat_id, cat_name, parent_id, is_show FROM ' . $GLOBALS['yp']->table('category') . 'WHERE is_show=1');

get_parent_cats 这个函数以上读取可用分类的时候,是通过 is_show=1 来读取的,但是如果上层有分类设置为 is_show=0 的话,那么下层的一些商品的详情页在这里读取上层分类数据的时候就会跳不出这个 while(1) 造成死循环了。

临时解决方法参考(标注 // Eric @20210217 的行是添加的):

function get_parent_cats($cat)
{
    if ($cat == 0)
    {
        return array();
    }

    $arr = $GLOBALS['db']->GetAll('SELECT cat_id, cat_name, parent_id, is_show FROM ' . $GLOBALS['yp']->table('category') . 'WHERE is_show=1');

    if (empty($arr))
    {
        return array();
    }

    $index = 0;
    $cats  = array();
    $flag = false; // Eric @20210217

    while (1)
    {
        $flag = false; // Eric @20210217
        
        foreach ($arr AS $row)
        {
            if ($cat == $row['cat_id'])
            {
                $cat = $row['parent_id'];

                $flag = true; // Eric @20210217
                
                $cats[$index]['cat_id']   = $row['cat_id'];
                $cats[$index]['cat_name'] = $row['cat_name'];
                $cats[$index]['parent_id'] = $row['parent_id'];
                $cats[$index]['is_show'] = $row['is_show'];

                $index++;
                break;
            }
        }

        if ($index == 0 || $cat == 0)
        {
            break;
        }
        
        // Eric @20210217
        if (!$flag)
        {
            break;
        }
    }

    return $cats;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant