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 --> 

    当你一步一个脚印的走过
  • 相关阅读:
    用js实现cookie的读、写、全部删除和删除指定cookie值的删除---源码
    JS手机号码格式验证
    vuex
    解决“此图片来自微信公众平台未经允许不可引用”的方法
    二叉树
    剑指 Offer 10- II. 青蛙跳台阶问题
    logrotate处理Gunicorn日志
    Linux日志切割神器logrotate原理介绍和配置详解
    Jenkins任务启动的后台进程被自动kill
    Flex、Grid、媒体查询实现响应式布局
  • 原文地址:https://www.cnblogs.com/Alviss/p/4572149.html
Copyright © 2011-2022 走看看