PHP+MYSQL page turner
Release: 2016-07-25 09:11:12
Original
1298 people have browsed it
In this program, the new class FENYE inherits the class DBSQL, so in the destructor of the new class, the destructor of the parent class is called to connect to the database, and the file config.inc.php that defines the global variables is also included.
- /*
- There are three class functions in this paging class. The function of the first function is mentioned above. The second function caculate is mainly to calculate the total number of records in the record set and how many to divide. The page is displayed, and these results are assigned to member variables so that the next function can use these values. The third function, url, is the code that implements paging display of the record set. Let me talk about it here. The paging algorithm mainly uses this SQL statement: select * from table_name limit $start, $pageper; among them, $start is the starting position of the query, and $pageper is the number of items to be displayed on each page. .
- */
- include_once("db.inc.php");
- class FENYE extends DBSQL{
- public $count_1; //Return the total number of result record sets
- private $pageper=3; //Each Number of record sets displayed on the page
- public $pc; //Total number of pages displayed
- private $sql="select * from students";
- public $offset; //Current page number
- public function __contract (){
- parent::__contract(); //Call the method in the parent class to connect to the database
- }
- public function caculate($sql=""){
- $sql=$this->sql;
-
- $result=mysql_query($sql) or die (mysql_error());
-
- $count=mysql_num_rows($result);
-
- $this->count_1=$count;
-
- $pc=intval($count /$this->pageper)+1;
-
- $this->pc=$pc;
-
- }
-
- public function url($targetUrl){
-
- $pagesize=$this->pageper ; // Display records on each page
-
- $page=isset($_GET['page'])?intval($_GET['page']):1;//Get the current page
-
- $sql="select * from students limit " .($page-1)*$pagesize.",$pagesize";
-
- //echo $sql ;exit;
-
- $results=mysql_query($sql) or die (mysql_error());
-
- while ($ row = mysql_fetch_array($results)){
-
- for($i=0;$i
- echo $row[$i]." " ;
- echo "
";
-
- }
-
- $offset=($page-1)*$pagesize;
-
- $prepage=$page-1; //Previous page
-
- $nextpage=$ page+1; //Next page
-
- $pagenav="Total ".$this->count_1." records Each page displays $pagesize records, a total of ".$this->pc." page, current Page $page";
-
- if($page==1){
-
- $strpage="[First page][Previous page][ Next page][Last page]";
-
- }
-
- if($page>1&&$page< ;=$this->pc){
-
- $strpage="[First page]【Previous page】【Next page】[Last page]";
-
- }
-
- if($page==$this->pc){
-
- $strpage="【First page】【Previous page】【Next Page】【Last page】";
-
- }
-
- $strpage="$pagenav
$strpage";
-
- echo $strpage;
-
- }
-
- }
-
-
- /*
- Small function annotation:
-
- intval: Get an integer value;
-
- count: Calculate the number of elements in an array;
-
- expression_1? expression_2:expression_3;: If the first expression is a value, the return value of this function is the value of the second expression, otherwise the return value of the function is the value of the third expression.
-
- For the safety of the program code, set the type of the member variables of the class to private. */
- ?>
Copy code
|
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31