刚完成的一个B2C商城里的商品中详情页需要显示用户评论数量,但是模板设计时,没有直接在library/comments.lbi里,所以直接在goods.dwt使用{$pager.record_count}调用显示不了!,1、在includes/lib_goods.php里面构建自定义函数:,/**此商品被评论次数,可以对评论加查询条件*/,function commentcount($goods_id)  {
$sql= "select count(*)  from ".$GLOBALS['ecs']->table('comment')." where id_value='".$goods_id."'  AND status = 1";
$res = $GLOBALS['db']->getOne($sql);
if($res>0)      {
return $res;
}     else      {
return('0');
}
},2、在根目录的goods.php的$smarty->assign('goods',              $goods);上面添加以下代码,$goods['comment_total_num'] = commentcount($goods_id);,3、在goods.dwt模板页面里使得以下代码显示,{$goods.comment_total_num},4、进入管理后台清空sql查询缓存,查看显示效果。,

刚完成的一个B2C商城里的商品中详情页需要显示用户评论数量,但是模板设计时,没有直接在library/comments.lbi里,所以直接在goods.dwt使用{$pager.record_count}调用显示不了!

1、在includes/lib_goods.php里面构建自定义函数:

/**此商品被评论次数,可以对评论加查询条件*/

function commentcount($goods_id)  {
$sql= "select count(*)  from ".$GLOBALS['ecs']->table('comment')." where id_value='".$goods_id."'  AND status = 1";
$res = $GLOBALS['db']->getOne($sql);
if($res>0)      {
return $res;
}     else      {
return('0');
}
}

2、在根目录的goods.php的$smarty->assign('goods',              $goods);上面添加以下代码

$goods['comment_total_num'] = commentcount($goods_id);

3、在goods.dwt模板页面里使得以下代码显示

{$goods.comment_total_num}

4、进入管理后台清空sql查询缓存,查看显示效果。

,

刚完成的一个B2C商城里的商品中详情页需要显示用户评论数量,但是模板设计时,没有直接在library/comments.lbi里,所以直接在goods.dwt使用{$pager.record_count}调用显示不了!

1、在includes/lib_goods.php里面构建自定义函数:

/**此商品被评论次数,可以对评论加查询条件*/

function commentcount($goods_id)  {
$sql= "select count(*)  from ".$GLOBALS['ecs']->table('comment')." where id_value='".$goods_id."'  AND status = 1";
$res = $GLOBALS['db']->getOne($sql);
if($res>0)      {
return $res;
}     else      {
return('0');
}
}

2、在根目录的goods.php的$smarty->assign('goods',              $goods);上面添加以下代码

$goods['comment_total_num'] = commentcount($goods_id);

3、在goods.dwt模板页面里使得以下代码显示

{$goods.comment_total_num}

4、进入管理后台清空sql查询缓存,查看显示效果。

最后修改:2025 年 09 月 10 日
如果觉得我的文章对你有用,请随意夸赞