PHP MySQL分頁顯示分析(2)_PHP教程
推薦:如何使用PHP中的字符串函數(shù)1)echo,print,printf,sprintf 前兩個函數(shù)是輸出字符串.字符串中如果有變量名則被替換成其值. 后兩個函數(shù)類似于C的同名函數(shù). (2)strchr,strlen,strtok,strrchr,strrev,strstr,strtolower
以下為引用的內容:
<html>
<head>
<title>php分頁示例</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<?php
conn=mysql_connect("localhost","root","");
//設定每一頁顯示的記錄數(shù)
pagesize=1;
mysql_select_db("mydata",conn);
//取得記錄總數(shù)rs,計算總頁數(shù)用
rs=mysql_query("select count(*) from tb_product",conn);
myrow = mysql_fetch_array(rs);
numrows=myrow[0];
//計算總頁數(shù)
pages=intval(numrows/pagesize);
if (numrows%pagesize)
pages ;
//設置頁數(shù)
if (isset(_GET['page'])){
page=intval(_GET['page']);
}
else{
//設置為第一頁
page=1;
}
//計算記錄偏移量
offset=pagesize*(page - 1);
//讀取指定記錄數(shù)
rs=mysql_query("select * from myTable order by id desc limit offset,pagesize",conn);
if (myrow = mysql_fetch_array(rs))
{
i=0;
?>
<table border="0" width="80%">
�。紅r>
�。紅d width="50%" bgcolor="#E0E0E0">
<p align="center">標題</td>
�。紅d width="50%" bgcolor="#E0E0E0">
<p align="center">發(fā)布時間</td>
�。�/tr>
<?php
do {
i ;
?>
�。紅r>
�。紅d width="50%"><?=myrow["news_title"]?></td>
<td width="50%"><?=myrow["news_cont"]?></td>
</tr>
�。�?php
}
while (myrow = mysql_fetch_array(rs));
echo "</table>";
}
echo "<div align='center'>共有".pages."頁(".page."/".pages.")";
for (i=1;i< page;i )
echo "<a href='fenye.php?page=".i."'>[".i ."]</a> ";
echo "[".page."]";
for (i=page 1;i<=pages;i )
echo "<a href='fenye.php?page=".i."'>[".i ."]</a> ";
echo "</div>";
?>
�。�/body>
�。�/html>
五、總結
分享:解決phpMyAdmin2.6以上版本數(shù)據(jù)的亂碼問題在phpMyAdmin2.6以上版本因為支持多語言集,弄得我們使用phpMyAdmin管理數(shù)據(jù)庫的時候,查詢出來的中文都是亂碼,但是在我們的PHP程序調用時卻沒有這些問題。 去phpMyAdmin2.6的根目錄下,
- 相關鏈接:
- 教程說明:
PHP教程-PHP MySQL分頁顯示分析(2)
。