zoukankan      html  css  js  c++  java
  • ecshop调用指定分类(包含子分类)下所有产品的评论信息

    调用指定分类(包含子分类)下所有产品的评论信息,使用了ecshop系统自带的函数get_children($cat_id)调用指定分类下所有子分类的id,该自带函数在文件include/lib_common.php文件内:

    /**
     * 获得指定分类下的商品评论
     * sun04zh3-20130321
     * @access   public
     * @param    integer $cat_id
     * @return   array
     */
    function get_comments_cat_id($cat_id)
    {
        $sql = 'SELECT c.id_value, c.user_name, c.content, c.add_time, p.goods_name, p.goods_thumb,p.goods_id  FROM '. 
                $GLOBALS['ecs']->table('comment') .' AS c '.
                ' LEFT JOIN '.$GLOBALS['ecs']->table('goods').' AS p ON p.goods_id = c.id_value '.
                ' WHERE c.comment_rank = 5 AND c.status = 1 AND c.id_value in (SELECT g.goods_id FROM '.
                $GLOBALS['ecs']->table('goods').'AS g '.'WHERE '.get_children($cat_id).') 
                ORDER BY c.comment_id DESC LIMIT 5';
        $res = $GLOBALS['db']->getAll($sql);
        $comment = array();
        foreach ($res AS $row)
        {
            $comment[] = array(
                               'id_value' => $row['id_value'],
                               'user_name'  => $row['user_name'],
                               'short_content'  => sub_str($row['content'],60),
                               'content'  => $row['content'],
                               'add_time' => date("Y-m-d H:i:s", $row['add_time']),
                               'goods_thumb' => $row['goods_thumb'],
                               'goods_short_name'  => sub_str($row['goods_name'],30),
                               'goods_name'  => $row['goods_name'],
                               'url' => build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']),);
        }
        return $comment;
    }

    category.php文件调用:

    $smarty->assign('comment',          get_comments_cat_id($cat_id));

    category.dwt文件显示:

    <!-- {foreach from=$commont item=com} -->
            <div class="pinglun-list">
                <div class="pinglun-photo">
                    <div class="pinglun-middle"><a href="{$com.url}"  title="{$com.goods_name}"><img src="{$com.goods_thumb}" width="78" height="58" border="0" /></a></div>
                </div>
                <div class="pinglun-name"><a href="{$com.url}"  title="{$com.goods_name}">{$com.goods_short_name}</a></div>
                <div class="pinglun-brief"><a href="{$com.url}" title="{$com.content}">{$com.short_content}</a></div>
            </div>
            <!--{/foreach}-->
  • 相关阅读:
    loj2042 「CQOI2016」不同的最小割
    loj2035 「SDOI2016」征途
    luogu2120 [ZJOI2007]仓库建设
    luogu3195 [HNOI2008]玩具装箱TOY
    51nod 1069 Nim游戏 + BZOJ 1022: [SHOI2008]小约翰的游戏John(Nim游戏和Anti-Nim游戏)
    HDU 5723 Abandoned country(最小生成树+边两边点数)
    BZOJ 1497: [NOI2006]最大获利(最大权闭合图)
    51nod 1615 跳跃的杰克
    SPOJ 839 Optimal Marks(最小割的应用)
    UVa 11107 生命的形式(不小于k个字符串中的最长子串)
  • 原文地址:https://www.cnblogs.com/shangxia/p/2973336.html
Copyright © 2011-2022 走看看