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

//判断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";    
         }  
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值