如何在分页中显示带有继续序列号的结果

时间:2014-09-17 04:52:16

标签: php mysqli

如何使用PHP分页从MySql表中显示继续序列号的结果

2 个答案:

答案 0 :(得分:0)

试试这个。这对我有用

  $pageno = $this->uri->segment(2); //  ( $this->uri->segment(2) ) : this is for codeigniter
  if(empty($pageno) || $pageno == 1){
    $srno = 1;
   } 
   else{ 
        $temp = $pageno-1; 
        $new_temp = $temp.'1'; 
        $srno = (int)$new_temp;
   }

答案 1 :(得分:-1)

尝试此功能将在php中显示序列号的分页。

http://code.stephenmorley.org/php/creating-pagination-links/

http://www.otallu.com/tutorials/simple-php-mysql-pagination/#sthash.7WPg1FdO.dpbs

或者您可以使用

function pagination($item_count, $limit, $cur_page, $link)
{
       $page_count = ceil($item_count/$limit);
       $current_range = array(($cur_page-2 < 1 ? 1 : $cur_page-2), ($cur_page+2 > $page_count ? $page_count : $cur_page+2));

       // First and Last pages
       $first_page = $cur_page > 3 ? '<a href="'.sprintf($link, '1').'">1</a>'.($cur_page < 5 ? ', ' : ' ... ') : null;
       $last_page = $cur_page < $page_count-2 ? ($cur_page > $page_count-4 ? ', ' : ' ... ').'<a href="'.sprintf($link, $page_count).'">'.$page_count.'</a>' : null;

       // Previous and next page
       $previous_page = $cur_page > 1 ? '<a href="'.sprintf($link, ($cur_page-1)).'">Previous</a> | ' : null;
       $next_page = $cur_page < $page_count ? ' | <a href="'.sprintf($link, ($cur_page+1)).'">Next</a>' : null;

       // Display pages that are in range
       for ($x=$current_range[0];$x <= $current_range[1]; ++$x)
               $pages[] = '<a href="'.sprintf($link, $x).'">'.($x == $cur_page ? '<strong>'.$x.'</strong>' : $x).'</a>';

       if ($page_count > 1)
               return '<p class="pagination"><strong>Pages:</strong> '.$previous_page.$first_page.implode(', ', $pages).$last_page.$next_page.'</p>';
}

<强>用法

pagination(
   total amount of item/rows/whatever,
   limit of items per page,
   current page number,
   url
);