PHP reads mysql database data and implements paging example code as follows:
- //Connect to the database
- $db =mysql_connect("localhost","root","root");
- mysql_select_db("gaoge",$db);
- //Set the number of records displayed on each page
- $pagesize=3;
-
- //Get the total number of records and calculate the total number of pages
- $res=mysql_query("select count(*) from image " ,$db);
- $myrow = mysql_fetch_array($res);
- //$myrow[o] is the sum of the total number of records in the database
- $numrows=$myrow[0];
- //echo "total num is:";
- //echo $numrows;
- // echo
;
- //Calculate the total number of pages
- $pages=intval($numrows/$pagesize);
-
- if ($numrows%$pagesize )
- $pages ;
- // echo "total pages is:";
- //echo $pages;
- //echo
;
- //Determine whether the page number is set or not, if not, it is defined as the home page
-
- if (isset($_GET[page])){
- //echo "page exist";
- $page = $_GET[page];
- //echo "enter if ";
- }
- else{
- //echo "page not exist";
- $page = 1;
- }
-
- //echo "page is:" ;
- // echo $page;
- // echo
;
- //Calculate record bias Offset
- $offset=$pagesize*($page-1);
- // echo "offset is:" ;
- echo $offset;
- //Get records
- $res=mysql_query("select * from image order by id desc limit $offset,$pagesize" ,$db);
- //Loop display records
- if ($myrow = mysql_fetch_array($res))
- {
- $i=0;
- ?>
- < ;table cellspacing=0 bordercolordark=#FFFFFF width="95%" bordercolorlight=#000000 border=1 align="center" cellpadding="2">
-
-
ID |
-
Picture name |
-
Uploader name |
-
Upload time | -
Picture effect |
-
-
-
- do {
- $i ;
- ?>
|
-
|
-
< ?php echo $myrow[2];?> |
-
|
-
|
-
-
- }
- while ($myrow = mysql_fetch_array ($res));
- echo "" ;
- }
- //Display the total number of pages
- echo "
There are ".$pages." pages (".$page."/".$pages.")
";
- //Display the number of pages
- for ($i=1;$i<=$pages;$i)
- echo "< ;a href=pages.php?page=".$i.">Page ".$i ." ";
- //echo "page is:";
- //echo "$page";
-
- // echo "
";
- //Display the page number
- echo "
- //Calculate the page values of the first page, previous page, next page and last page
- $ first=1;
- $prev=$page-1;
- $next=$page 1;
- $last=$pages;
-
- echo "Homepage ";
- //echo "page is:";
- //echo "$page";
- echo "Previous page ";
-
- echo "Next page ";
- echo "Last page ";
-
- echo "";
- echo "
";
- ?>
-
http://www.bkjia.com/PHPjc/486122.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486122.htmlTechArticlePHP reads mysql database data and implements paging example code as follows: ?php //Connect to the database $db=mysql_connect( "localhost","root","root"); mysql_select_db("gaoge",$db); //Set each page to display...
Statement: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