A classic php mysql paging program_PHP tutorial

WBOY
Release: 2016-07-13 17:05:19
Original
3529 people have browsed it

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);

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630790.htmlTechArticleA classic php mysql paging program. This article provides a php paging code, which is relatively simple and common. The limit comes in for paging, and it also has a conditional query paging function. A classic...
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