本文目錄一覽:
- 1、求簡單的php分頁代碼一定要是簡單最好可以詳細解釋的,如果可以希望高手能把這段代碼加上分頁
- 2、將分頁的PHP代碼封裝成函數在查詢頁面怎麼調用?
- 3、關於PHP分頁
- 4、php thinkphp3.2.3怎麼做分頁樣式
求簡單的php分頁代碼一定要是簡單最好可以詳細解釋的,如果可以希望高手能把這段代碼加上分頁
body
?
/*
‘PID 頁面中的其它傳參連接
‘page 要顯示的頁碼
‘Vcount 總記錄數
‘Pnum 每頁記錄數
‘className 超連接樣式
*/
function ThePage($Pid,$page=1,$Vcount,$Pnum,$className){
$Pcount = ceil($Vcount/$Pnum);
if($page$Pcount) $page=$Pcount;
$StartPageNum=1;
while($StartPageNum+10=$page){
$StartPageNum=$StartPageNum+10;
}
$EndPageNum=$StartPageNum+9 ;
if($EndPageNum$Pcount) $EndPageNum=$Pcount;
$show = $show.”trtd colspan=’10’ bgcolor=” align=’right’ style=’padding-right:25px;padding-top:5px;’ class='”.$className.”‘”;
$show = $show.”共b”.$Pcount.”/b頁 共有b”.$Vcount.”/b記錄 第b”.$page.”/b頁 跳到第 [ “;
if($StartPageNum1) $show = $show.”a class='”.$className.”‘ href=’?”.$Pid.”page=”.($StartPageNum-1).”‘ title=’前十頁’font face=’webdings’7/font/a”;
for($go=$StartPageNum;$go=$EndPageNum;$go++){
if($go!=$page){
$show = $show.”a class='”.$className.”‘ href=’?”.$Pid.”page=”.$go.”‘”.$go.”/a”;
}else{
$show = $show.”b”.$go.”/b”;
}
$show = $show.” “;
}
if($EndPageNum$Pcount) $show = $show.”a class='”.$className.”‘ href=’?”.$Pid.”page=”.($EndPageNum+1).”‘ title=’下十頁’font face=’webdings’8/font/a”;
$show = $show.”] 頁”;
if($page!=1) $show = $show.”a class='”.$className.”‘ href=’?”.$Pid.”page=1′ 首頁/a a class='”.$className.”‘ href=’?”.$Pid.”page=”.($page-1).”‘上一頁/a”;
if($Pcount-$page!=0) $show = $show. “a class='”.$className.”‘ href=’?”.$Pid.”page=”.($page+1).”‘ 下一頁/a a class='”.$className.”‘ href=’?”.$Pid.”page=”.$Pcount.”‘尾頁/a”;
$show=$show.”/tr/td”;
return $show;
}
?
?php
//連上資料庫
mysql_connect(“localhost”,”root”,””);
//選擇資料庫
mysql_select_db(“company”);
//執行資料庫命令
mysql_query(“set names ‘utf8′”);
//關閉資料庫就是使用的最近的資料庫
echo “afont color=red已查到的記錄:/font/a”.”font color=red
共”.mysql_num_rows
($rs).”條/font”.”br”.”br”;
?
input type=”button” value=”添加員工” onclick=”location.href=’empadd.html'” /
form class=”bd”
table border=”1″ align=”left” bordercolor=”blue” background=”27[1].jpg”
td align=”center”font color=#0000FF職員編號/font/td
td align=”center”font color=#0000FF職員姓名/font/td
td align=”center”font color=#0000FF職員職位/font/td
td align=”center”font color=#0000FF職員經理/font/td
td align=”center”font color=#0000FF入職日期/font/td
td align=”center”font color=#0000FF職員工資/font/td
td align=”center”font color=#0000FF所在部門/font/td
td align=”center” width=”100″ height=”20″font color=#0000FF操作/font/td
/tr
?
//設置參數
$page = $_REQUEST[“page”];
if($page==””) $page = 1;
$Pid = “”;
$Pnum = 10;
$classname = “lwf”;
//以下不用修改
$rs = mysql_query(“select count(*) from emp e1 left join emp e2 on e1.mgr = e2.empno left join dept on e1.deptno = dept.deptno”);
$Vcount = @mysql_result($rs,0);
@mysql_free_result($rs);
$start = ($page – 1) * $Pnum;
$lastNum = $Vcount – ($page – 1) * $Pnum;
$limit = $lastNum $Pnum ? $Pnum : $lastNum;
$rs = mysql_query(“select e1.empno, e1.ename, e1.job, e1.mgr, e1.hiredate, e1.sal, e1.deptno, e2.ename as mname, dname from emp e1 left join emp e2 on e1.mgr = e2.empno left join dept on e1.deptno = dept.deptno LIMIT $start,$limit”);
while($ary = mysql_fetch_array($rs)){
?
tr bordercolor=”blue”
td width=”80″ height=”20″ align=”center”?php echo $a[“empno”];? /td
td width=”80″ height=”20″ align=”center”?php echo $a[“ename”];? /td
td width=”80″ height=”20″ align=”center”?php echo $a[“job”];? /td
td width=”80″ height=”20″ align=”center”?php echo $a[“mname”];? /td
td width=”150″ height=”20″ align=”center”?php echo $a[“hiredate”];? /td
td width=”80″ height=”20″ align=”center”?php echo $a[“sal”];? /td
td width=”80″ height=”20″ align=”center”?php echo $a[“dname”];? /td
td width=”90″ height=”20″ align=”center”
a href=”empedit.php?aa=?php echo $a[’empno’]?”修改/a |
a href=”empdel.php?aa=?php echo $a[’empno’]?”刪除/a/td
/tr
?
}
@mysql_free_result($rs);
echo ThePage($Pid,$page,$Vcount,$Pnum,$classname);
?
/table
/form
/body
將分頁的PHP代碼封裝成函數在查詢頁面怎麼調用?
難道不是
echo pageshwo(Sql語句,顯示欄位數)?
這個只是顯示分頁鏈接的。應該還有一個別的類用於顯示數據的吧
關於PHP分頁
一個分頁函數,賦好值就可以使用了
/*
‘PID 頁面中的其它傳參連接
‘page 要顯示的頁碼
‘Vcount 總記錄數
‘Pnum 每頁記錄數
‘className 超連接樣式
*/
function ThePage($Pid,$page=1,$Vcount,$Pnum,$className){
$Pcount = ceil($Vcount/$Pnum);
if($page$Pcount) $page=$Pcount;
$StartPageNum=1;
while($StartPageNum+10=$page){
$StartPageNum=$StartPageNum+10;
}
$EndPageNum=$StartPageNum+9 ;
if($EndPageNum$Pcount) $EndPageNum=$Pcount;
$show = $show.”trtd colspan=’10’ bgcolor=” align=’right’ style=’padding-right:25px;padding-top:5px;’ class='”.$className.”‘”;
$show = $show.”共b”.$Pcount.”/b頁 共有b”.$Vcount.”/b記錄 第b”.$page.”/b頁 跳到第 [ “;
if($StartPageNum1) $show = $show.”a class='”.$className.”‘ href=’?”.$Pid.”page=”.($StartPageNum-1).”‘ title=’前十頁’font face=’webdings’7/font/a”;
for($go=$StartPageNum;$go=$EndPageNum;$go++){
if($go!=$page){
$show = $show.”a class='”.$className.”‘ href=’?”.$Pid.”page=”.$go.”‘”.$go.”/a”;
}else{
$show = $show.”b”.$go.”/b”;
}
$show = $show.” “;
}
if($EndPageNum$Pcount) $show = $show.”a class='”.$className.”‘ href=’?”.$Pid.”page=”.($EndPageNum+1).”‘ title=’下十頁’font face=’webdings’8/font/a”;
$show = $show.”] 頁”;
if($page!=1) $show = $show.”a class='”.$className.”‘ href=’?”.$Pid.”page=1′ 首頁/a a class='”.$className.”‘ href=’?”.$Pid.”page=”.($page-1).”‘上一頁/a”;
if($Pcount-$page!=0) $show = $show. “a class='”.$className.”‘ href=’?”.$Pid.”page=”.($page+1).”‘ 下一頁/a a class='”.$className.”‘ href=’?”.$Pid.”page=”.$Pcount.”‘尾頁/a”;
$show=$show.”/tr/td”;
return $show;
}
========================附帶一個使用例子=============================
?
//設置參數
$page = $_REQUEST[“page”];
if($page==””) $page = 1;
$T = $_GET[“T”];
if($T==””) $T = 1;
$Pid = “T=”.$T.””;
$wheresql = “where T = “.$T;
$recordListTable = “zc_news”;
$Pnum = 10;
$classname = “lwf”;
//以下不用修改
$rs = mysql_query(“select count(*) from `”.$recordListTable.”` $wheresql “);
$Vcount = @mysql_result($rs,0);
@mysql_free_result($rs);
$start = ($page – 1) * $Pnum;
$lastNum = $Vcount – ($page – 1) * $Pnum;
$limit = $lastNum $Pnum ? $Pnum : $lastNum;
$rs = mysql_query(“select * from `”.$recordListTable.”` $wheresql order by orderid desc,ID desc LIMIT $start,$limit”);
while($ary = mysql_fetch_array($rs)){
?
tr
td標題/td
/tr
?
}
@mysql_free_result($rs);
echo ThePage($Pid,$page,$Vcount,$Pnum,$classname);
?
php thinkphp3.2.3怎麼做分頁樣式
$id = I(“id”);
$Cate = M(‘Article’); // 實例化Cate對象
$count = $Cate-where(“cate=$id”)-count(); // 查詢滿足要求的總記錄數
$Page = new \Think\Page($count, 32); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)
$Page-setConfig(‘header’, ‘條數據’);
$Page-setConfig(‘prev’, ‘上一頁’);
$Page-setConfig(‘next’, ‘下一頁’);
$Page-setConfig(‘first’, ‘首頁’);
$Page-setConfig(‘end’, ‘末頁’);
$show = $Page-show(); // 分頁顯示輸出
$list = $Cate-where(“cate=$id”)-order(‘id DESC’)-limit($Page-firstRow . ‘,’ . $Page-listRows)-select();
$this-assign(‘list’, $list); // 賦值數據集
$this-assign(‘page’, $show); // 賦值分頁輸出
//大家都在看
$click = M(‘article’)-limit(8)-order(“click DESC”)-select();
$this-assign(‘click’, $click);
//最新資訊
$news = M(‘article’)-limit(8)-order(“click DESC”)-select();
$this-assign(‘news’, $news);
$this-display();
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/235602.html