ecshop首页调用评论函数(index.php)(2012-02-21 14:57:07)
1. function comments_info($count=1) { $sql = "SELECT g.goods_id,g.goods_name,g.goods_thumb,tb.ct FROM ". $GLOBALS['ecs']->table('goods'). " g join". "(select id_value id,count(*) ct from ". $GLOBALS['ecs']->table('comment')." where comment_type=0 and status=1 group by id_value) tb ". "on g.goods_id=tb.id "; if(!empty($count)) $sql.=" limit 0,".$count; $res = $GLOBALS['db']->getAll($sql); $arr = array(); foreach ($res AS $i => $row) { $arr[$i]['goods_id']=$row['goods_id']; $arr[$i]['goods_name']=$row['goods_name']; $arr[$i]['count']=$row['ct']; $arr[$i]['goods_thumb']=$row['goods_thumb']; $arr[$i]['comment']= get_comment($row['goods_id']); } return $arr; }
function get_comment($goodid=0) { $sql = "SELECT * FROM ". $GLOBALS['ecs']->table('comment')." WHERE `id_value`=". $goodid." and status=1 order by `parent_id`,`add_time` LIMIT 0,4"; return $GLOBALS['db']->getAll($sql); }
2.
$smarty->assign('comment_list', comments_info(10)); // 商品评论
3.
<!--商品评论开始{if $comment_list}-->
<div style="overflow:hidden;height:190px;" id="demo"> <div id="demo1"> <ul> <!--{foreach from=$comment_list item=comm}--> <li> <div class="fl"><a href="goods.php?id={$comm.goods_id}" title="{$comm.goods_name}" target="_blank"> <img alt="{$comm.goods_name}" src="{$comm.goods_thumb}" style="width:80px;"></a> </div> <div class="fl " style="padding-top:5px;width:350px;"> <!--{foreach from=$comm.comment item=info}--> <!--{if $info.user_name}--> <font class="bl" >{$info.user_name}</font>:<a href="goods.php?show=a&id={$comm.goods_id}" target="_blank"> {$info.content}</a> <br/> <!--{/if}--> <!--{/foreach}--> </div> </li> <!--{/foreach}--> </ul> </div> <div id="demo2"></div> </div>
<!--商品评论结束{/if}-->
|