推56论坛

 找回密码
 立即注册(限中文)

QQ登录

只需一步,快速开始

    查看: 129|回复: 0

    [ECshop教程] ecshop显示当前商品分类或显示下级分类函数

    [复制链接]
    发表于 2018-4-28 18:53:49 | 显示全部楼层 |阅读模式
    function get_categories_tree_xaphp($cat_id = 0)
    {
    if ($cat_id > 0)
    {
    $sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$cat_id'";
    $parent_id = $GLOBALS['db']->getOne($sql);
    }
    else
    {
    $parent_id = 0;
    }
    /*
    判断当前分类中全是是否是底级分类,
    如果是取出底级分类上级分类,
    如果不是取当前分类及其下的子分类
    */
    $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$cat_id' AND is_show = 1 ";
    if ($parent_id == 0||$GLOBALS['db']->getOne($sql))
    {
    /* 获取当前分类及其子分类 */
    $sql = 'SELECT cat_id,cat_name ,parent_id,is_show ' .
    'FROM ' . $GLOBALS['ecs']->table('category') .
    "WHERE parent_id = '$cat_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";
    $res = $GLOBALS['db']->getAll($sql);
    foreach ($res AS $row)
    {
    if ($row['is_show'])
    {
    $cat_arr[$row['cat_id']]['id'] = $row['cat_id'];
    $cat_arr[$row['cat_id']]['name'] = $row['cat_name'];
    $cat_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
    }
    }

    }
    else
    {


    /* 获取当前分类及其子分类 */
    $sql = 'SELECT cat_id,cat_name ,parent_id,is_show ' .
    'FROM ' . $GLOBALS['ecs']->table('category') .
    "WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";

    $res = $GLOBALS['db']->getAll($sql);

    foreach ($res AS $row)
    {
    if ($row['is_show'])
    {
    $cat_arr[$row['cat_id']]['id'] = $row['cat_id'];
    $cat_arr[$row['cat_id']]['name'] = $row['cat_name'];
    $cat_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
    }
    }
    }
    if(isset($cat_arr))
    {
    return $cat_arr;
    }
    }

    学建站、学推广、学赚钱,上56站长论坛就够了!个性签名请到个人资料里面修改……

    本版积分规则

    关闭

    推56站长论坛推荐上一条 /3 下一条

    站长QQ
    在线咨询
    咨询热线
    QQ:405327411
    站长

    QQ|广告合作|关于我们|联系我们|免责声明|网站导航|站长论坛 ( 豫ICP备11018337号-5

    王宝臣旗下网站 推56论坛(www.tui56.com|ask.tui56.com|blog.tui56.com|daohang.tui56.com)

    Powered by Discuz! X3.4 Licensed

    ©2001-2013 Comsenz Inc.

    快速回复 返回顶部 返回列表