Home >Backend Development >PHP Tutorial >A classic php mysql paging program_PHP tutorial
A classic php mysql paging program This article provides a PHP paging code. This is a relatively simple and common limit to paginate. At the same time, it also has a conditional query paging function.
A classic php tutorial mysql tutorial paging program
This article provides a PHP paging code. This is a relatively simple and common limit to paginate. At the same time, it also has a conditional query paging function.
*/
$conn=mysql_connect($mysql_host,$mysql_user,$mysql_password) or die('Error connecting to server');
mysql_select_db($mysql_db) or die("Error in selecting database tutorial");
mysql_query("set names 'gbk'");
function table($t)
{
global $mysql_table_prefix;
return $mysql_table_prefix.$t;
}
$sql="select * from ".table('keywords')." where 1=1 ";
$sql2="select count(*) from ".table('keywords')." where 1=1 ";
$py=trim($_request['py']);
if($act=="search" and !empty($_post['s1']))
{
$s1=trim($_post['s1']);//Get the search word
$sql .=" and (k1='$s1' or k2='$s1') ";
$sql2 .=" and (k1='$s1' or k2='$s1') ";
}
elseif(!empty($py))
{
$sql .=" and pinyin='$py' ";
$sql2.=" and pinyin='$py' ";
}
$sql .=" order by pinyin ";
$rscount=mysql_query($sql2);
$rscount=@mysql_fetch_array($rscount);
$rscount=$rscount[0];//Get the total number of records$page=trim($_get['page']);//Current page number
$pagesize=30;//Number of records per page
$pagecount=ceil($rscount/$pagesize);//Get the total number of pages
$pageurl="";
if($page<=1)
{
$page=1;
$pageurl.="Home Page Previous Page";
}else
{
$pageurl .=" Homepage Previous page";
}
if($page>=$pagecount)
{
$page=$pagecount;
$pageurl .="Next page Last page";
}else
{
$pageurl .=" Next page Last page";
}$start_rs=($page-1)*$pagesize;//Start
$end_rs=$page*$pagesize;//End
$sql .=" limit {$start_rs},{$end_rs} ";
$res=mysql_query($sql);?>