Ecshop判断ID为父类或子类,是父类则获取下级子类

来源:互联网 发布:windows最佳分辨率 编辑:程序博客网 时间:2024/06/05 01:07
//判断ID是否为父类,如果是父类,则返回0,执行下一函数get_child()
function get_Is_parent()
{
  $id=$_GET["id"];
  $sql="select sum(parent_id) from ecs_category where cat_id=$id ";
  $val = intval($GLOBALS['db']->getOne($sql));
  return $val;

}


//通过以上函数判断为父类,则取出父类下的子类ID
function get_child()
{
    $cat=$_GET['id'];
    if ($cat == 0)
    {
        return array();
    }
    $arr = $GLOBALS['db']->GetAll('select cat_id from ecs_category where parent_id='.$cat);
    if (empty($arr))
    {
        return array();
    }
    $cats  = array();
    $index = 0;
    foreach ($arr AS $row)
    {
        if($index==0)
          $c_id.=$row['cat_id'];
        $c_id.=",".$row['cat_id'];
        $index++;
    }
    return  $c_id;

}


function hot_category_goods()

{
        $id=$_GET['id']; 

       //判断ID是否为父类
        if(get_Is_parent()==0)
        {

             //ID为父类,则获取父类下的子类

              echo "g.cat_id in (".get_child().") and is_hot=1";
        }

        //ID为子类,执行此代码

         else
         {   
          echo "g.cat_id=$id and is_hot=1";    
         }  
 }

原创粉丝点击