-
- /**
- Class to paginate queries
- @link http://bbs.it-home.org
- */
- class paging
- {
- private $pageSize; //The number of items displayed on each page. The default is 10 items.
- private $totlePage; //How many records are there in total? private $dbConnection; //Database connection
- private $nowPageIndex; //The number of pages currently displayed
- private $show; //Use that method to display navigation, the default method It is the method of using show1() Home Page | Previous Page | Next Page | Last Page.
- /**
- Constructor to establish a database connection
- @$pageSizeP The number of items displayed on each page is 10 by default.
- @$show Which method to use to display navigation, the default method is to use show1() Home page | Previous page | Next page | Last page.
- */
- public function _construct($pageSizeP=10,$show="show1")
- {
- $this->dbConnection = @mysql_connect("localhost","username","password" );
- if($this->dbConnection)
- {
- die("");
- }
- mysql_select_db($this->dbConnection,"databaseName");
- $this->show = $show;
- $this->pageSize = $pageSizeP;
- }
- /**
- Destructor, closes the database connection.
- */
- public function _destruct()
- {
- @mysql_close($this->dbConnection);
- }
- /**
- Query the database and display the number of records in the database.
- @$sql SQL statement to query the database.
- @$charset queries the character set used by the database. The default is UTF-8.
- @return Returns the result of database query, saves it as an array, and then returns it, the number of items is uncertain.
- */
- public function querySQL($sql,$charset="UTF-8")
- {
- mysql_query("SET NAMES ".$charset);
- $rs = @mysql_query($sql);
- if(!$rs )
- {
- die("");
- }
- $num = @mysql_num_rows($rs);
- $this->totlePage= ceil($num/$this->pageSize);
- $this-> nowPageIndex = (isset($_POST['page']) || $_POST['page'] >= 1):$_POST['page']?1;
- if($this->nowPageIndex >$ this->totlePage)
- {
- $this->nowPageIndex = $this->totlePage;
- }
- $start = ($this->nowPageIndex - 1)*$this->pageSize;
- mysql_free_result( $rs);
- $sql .= "LIMIT $start,$this->pageSize";
- $rs = @mysql_query($sql);
- if(!$rs)
- {
- die("");
- }
- $rows = array();
- while($row = @mysql_fetch_row($rs))
- {
- $rows[] = $row;
- }
- @mysql_free_result($rs);
- return $rows;
- }
- /**
- Show navigation orchid.
- @$arg Parameters for calling the function that displays navigation.
- $img1 is an array that saves the images of navigation connections. used when calling show1().
- $size is the number of pages displayed in one row of the navigation blueprint. used when calling show2().
- */
- public function show($arg)
- {
- $func = $this->show;
- $this->$func($arg);
- }
- /**
- The navigation is displayed in the order of Home Page | Previous Page | Next Page | Last Page.
- @$img1 The image path array corresponding to the home page | previous page | next page | last page. The default is NULL, which does not display images.
- */
- private function show1($img1 = NULL)
- {
- $url = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
- $str = "
|