- 相關(guān)推薦
一段經(jīng)典php mysql分頁程序代碼
學習既是從基礎(chǔ)的學起,也是從經(jīng)典的例子中學起。以下百分網(wǎng)小編整理的一段經(jīng)典php mysql分頁程序代碼,歡迎練習!
$conn=mysql_connect($mysql_host,$mysql_user,$mysql_password) or die('連接服務器出錯');mysql_select_db($mysql_db) or die("選擇數(shù)據(jù)庫教程出錯");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];//獲取總記錄數(shù)
$page=trim($_get['page']);//當前頁數(shù)
$pagesize=30;//每頁記錄數(shù)
$pagecount=ceil($rscount/$pagesize);//獲取總頁數(shù)$pageurl="";if($page<=1)
{
$page=1;
$pageurl.=" 首頁 上一頁";
}else
{
$pageurl .=" <a href='?page=1&py=".$py."'>首頁</a> <a href='?py=".$py."&page=".($page-1)."'>上一頁</a>";}
if($page>=$pagecount)
{
$page=$pagecount;
$pageurl .=" 下一頁 尾頁";
}else
{
$pageurl .=" <a href='?py=".$py."&page=".($page+1)."'>下一頁</a> <a href='?py=".$py."&page=".$pagecount."'>尾頁</a>";}
$start_rs=($page-1)*$pagesize;//開始
$end_rs=$page*$pagesize;//結(jié)束
$sql .=" limit {$start_rs},{$end_rs} ";
$res=mysql_query($sql);
?>
【一段經(jīng)典php mysql分頁程序代碼】相關(guān)文章:
php查詢mysql的實例03-29
PHP常用MySql操作的方法03-27
php+mysql注射語句構(gòu)造12-04
PHP中MySql操作是什么11-17