zoukankan      html  css  js  c++  java
  • 自定义调用 ecshop 分页代码(转)

    自定义调用 ecshop 分页代码

    原文出处:http://blog.sina.com.cn/s/blog_6479ae370100hsq6.html

         function get_comments($num,$start)
    {
      
       $sql =" SELECT * FROM ecs_comment WHERE status = 1 AND parent_id = 0 and comment_type=0 ORDER BY add_time DESC  limit $start, $num";
     
      //echo $sql;  
      //$res = $GLOBALS['db']->SelectLimit($sql, $num, $start);    
      $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'];
       $comments[$idx]['add_time']       = local_date("Y-m-d H:i:s",$row['add_time']);
       $comments[$idx]['goods_name']     = $GLOBALS['db'] -> getOne("select goods_name from ecs_goods where goods_id = ".$row['id_value']);
       $comments[$idx]['shop_price']     = $GLOBALS['db'] -> getOne("select shop_price from ecs_goods where goods_id = ".$row['id_value']);
       $comments[$idx]['replay']         = $GLOBALS['db'] -> getOne("select content from ecs_comment where parent_id = ".$row['comment_id']);
       $comments[$idx]['shop_price']     = price_format($comments[$idx]['shop_price']);
      }
      return $comments;
    }

         取部分分页数据,条数用limit控制,$start,$num表示分页起始位置.

         $sql = "SELECT COUNT(*) FROM  ecs_comment";
        $record_count = $GLOBALS['db']->getOne($sql);
     $page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
      
        $pager = get_pager('ping.php', array(), $record_count, $page, 10);//php页面是当前页面
        $msg_lists = get_comments(10, $pager['start']);
      
        $GLOBALS['smarty']->assign('rand',      mt_rand());
       
        $GLOBALS['smarty']->assign('pager', $pager);
        $GLOBALS['smarty']->assign('my_comments',$msg_lists);

        把分页的数据拿过来,给smarty,取页面ID.这里有ecshop中的get_pager函数,来处理分页.

       最后在模板中加上翻页模板

        <!-- #BeginLibraryItem "/library/pages.lbi" --><!-- #EndLibraryItem --> 

    当你一步一个脚印的走过
  • 相关阅读:
    linux svn切换用户
    解决QQ“抱歉,无法发起临时会话,您可以 添加对方为好友以发送消息”
    node.js中http.respone.end方法概述
    niginx:duplicate MIME type "text/html" in nginx.conf 错误(转载)
    大三暑假实习,我们可以怎么做
    一个Java程序员的实习总结(2)
    正式工作的前奏——一个Java程序员的实习总结(1)
    【个人】当我秀智商的时候我秀什么
    基于java的设计模式入门(1)——为什么要学习设计模式
    【个人】我不愿让你一个人
  • 原文地址:https://www.cnblogs.com/Alviss/p/4572149.html
Copyright © 2011-2022 走看看