分享电子商务心得

ECSHOP首页如何调用产品最新评论

2009-07-16  |  22:35分类:电子商务程序优化  |  971 views

首先,在库目录里增加一个文件:Newcomments.lbi 将以下内容加入此文件:

<?php
if(!function_exists(”get_comments”)){
function get_comments($num)
{
   $sql = ‘Select * FROM ecs_comment ‘.
            ‘ Where status = 1 AND parent_id = 0 and comment_type=0 ‘.
            ‘ orDER BY add_time DESC’;
  if ($num > 0)
  {
   $sql .= ‘ LIMIT ‘ . $num;
  }
  //echo $sql;
       
  $res = $GLOBALS['db']->getAll($sql);
  $comments = array();
  foreach ($res AS $idx => $row)
  {

   $comments[$idx]['user_name']       = $row['user_name'];
   $comments[$idx]['content']       = $row['content'];
            $comments[$idx]['id_value']       = $row['id_value'];

  }
  return $comments;
}
}

?>

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>

       <!–数据调用-最新评论开始 –>      
    <?php
        $this->assign(’my_comments’,get_comments(5)); // 5代表会条数据
    ?>        
此处是循环输出评论内容:
<!–{foreach from=$my_comments item=comments}–>
      <li><a href=”goods.php?id={$comments.id_value}” target=”_blank”>{$comments.content|truncate:10:”"}</a></li>
      <!–{/foreach}–>

然后以上内容只是功能显示,在相应处加入你需要的样式即可。
最后,首页调用此库文件就可以了.

<!– #BeginLibraryItem “/library/Newcomments.lbi” –>  <!– #EndLibraryItem –>

bouncer

喜欢本文,那就收藏到: Google书签 Digg Live Bookmark Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网

发表您的评论