search
Homephp教程php手册一款经典php mysql分页程序

一款经典php mysql分页程序

Jun 13, 2016 am 10:08 AM
mysqlphpcodePaginationsupplyarticleprogramclassic

一款经典php mysql分页程序 本文章提供一款php分页代码,这是一款比较简单也常的limit进来分页了,同时他还带有条件查询分页功能。

一款经典php教程 mysql教程分页程序
本文章提供一款php分页代码,这是一款比较简单也常的limit进来分页了,同时他还带有条件查询分页功能。
*/

$conn=mysql_connect($mysql_host,$mysql_user,$mysql_password) or die('连接服务器出错');
mysql_select_db($mysql_db) or die("选择数据库教程出错");
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']);//获取搜索字
 $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];//获取总记录数

$page=trim($_get['page']);//当前页数
$pagesize=30;//每页记录数
$pagecount=ceil($rscount/$pagesize);//获取总页数
$pageurl="";
if($page {
 $page=1;
 $pageurl.=" 首页 上一页";
}else
{
 $pageurl .=" 首页  上一页";
}
if($page>=$pagecount)
{
 $page=$pagecount;
 $pageurl .=" 下一页  尾页";
}else
{
 $pageurl .=" 下一页  尾页";
}

$start_rs=($page-1)*$pagesize;//开始
$end_rs=$page*$pagesize;//结束
$sql .=" limit {$start_rs},{$end_rs} ";
$res=mysql_query($sql);

?>

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor