mysql paging php5 mysql paging example code

WBOY
Release: 2016-07-29 08:37:53
Original
1026 people have browsed it

Copy the code The code is as follows:


//Connect to the database
$db=mysql_connect("localhost","root","");
mysql_select_db("hy",$db);
//Set the content displayed on each page Number of records
$pagesize=25;
//Get the total number of records and calculate the total number of pages using
$res=mysql_query("select count(*) from main " " ,$db);
$myrow = mysql_ fetch_array($res);
$numrows=$myrow[0];
//Calculate the total number of pages
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
$pages++;

//Determine the page number setting or not, if not, it is defined as the homepage
if (!isset($page))
$page=1;
//Judge the number of pages to go to
if (isset($ys))
if ($ys>$pages )
$page=$pages;
else
$page=$ys;
//Calculate the record offset
$offset=$pagesize*($page-1);
//Get the record
$res=my sql_query( "select id,title from main order by id desc limit $offset,$pagesize" ,$db);
//Loop display of records
if ($myrow = mysql_fetch_array($res))
{
$i=0;
?> FB ">
Content< /td>                                                    td width="5%" bgcolor="#E6F2FF">< ?php echo $i;?>

< /font>

}
while ($myrow = mysql_fetch_array($res));
echo "" ; ;
}
//Show the total number of pages
echo "

There are ".$pages." pages (".$page."/".$pages.")
";
//Display the number of pages
for ($i=1;$i<$page;$i++)
echo "Page". $i ."Page "; ";
echo ".$page."Page ";
for ($i=$page+1;$i<=$pages;$i++)
echo "< ;a href='fenye.php?page=".$i."'>Page ".$i ." Number of pages                                                                                                                                                                                                                                           ​$prev=$page-1;
$next=$page+1;
$last=$pages;
if ($page>1)
{
echo "Homepage ​ ";
}
if ($page<$pages)
{
echo "Next page ";
echo " Last page '2' value=".$page.">page";
echo "";
echo "";
echo "
";
?>



The above introduces the mysql paging php5 mysql paging example code, including the content of mysql paging. I hope it will be helpful to friends who are interested in PHP tutorials.


Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template