自定义调用 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 -->