PHP Simple Page-type

Source: Internet
Author: User
Tags count sql php class php code reset

This is a simple and easy to use paging class. Just add two sentences to your original program and change the sentence.
Post Code First
paging.php


PHP Code
		
			<?php class Paging {public static $count = 0;
  public static $size = 0;
  public static $page = 0;
    static function Prepare ($sql, $pagesize =10) {$page = isset ($_get[' page '))? $_get[' page ': 1;
    $pageon = ($page-1) * $pagesize; $sql = preg_replace ('/select\s/i ', ' $0sql_calc_found_rows ', $sql).
    "Limit $pageon, $pagesize";
    $rs = mysql_query ($sql);
    $p = mysql_query (' SELECT found_rows () ');
    List (self:: $count) = Mysql_fetch_row ($p);
    Self:: $size = $pagesize;
    Self:: $page = $page;
  return $rs; The static function bar ($tpl = ') {if (! $tpl) $tpl = ' <a href=?reset> home </a> <a href=?prve> prev &LT;/A&G T
    <a href=?next> Next page </a> <a href=?end> last </a> ';
    $count = Ceil (self:: $count/self:: $size);
    $page = self:: $page;
    unset ($_get[' page '));  $d = Array (' Reset ' => 1, ' Prve ' => $page > 1? $page-1:1, ' Next ' => $page < $count? $page + 1: $count, ' End ' => $count,);
      foreach ($d as $k => $v) {$_get[' page '] = $v;
    $TPL = Str_replace ($k, Http_build_query ($_get), $TPL);
  Echo $tpl;
 }
}

Usually you have a statement like this $sql = "..."; $rs = mysql_query ($sql); or $rs = mysql_query ("SELECT ..."); You only need to change to include ' paging.php '; $rs = paging::p repare ($sql, Number of rows per page); Write Paging::bar () where the paging bar is required; It's OK, it's very simple!



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.