亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

我的分頁封裝后,點擊上下一頁,首尾都不管用??!

分頁:

function showPage($page,$totalPage,$where=null,$sep=" "){

//分頁條件

$where=($where == null)?null:"&".$where;

$url=$_SERVER['PHP_SELF'];//得到當前腳本的路徑

//首頁

$index=($page==1)?"首頁":"<a href='{$url}?page=1{$where}'>首頁</a>";

//尾頁

$last=($page==$totalPage)?"尾頁":"<a href='{$url}?page={$totalPage}{$where}'>尾頁</a>";

//上一頁

$prevPage=($page>=1)?$page-1:1;

$nextPage=($page>=$totalPage)?$totalPage:$page+1;

$prev=($page==1)?"上一頁":"<a href='{$url}?page={$prevPage}{$where}'>上一頁</a>";

//下一頁

$next=($page==$totalPage)?"下一頁":"<a href='{$url}?page={$nextPage}{$where}'>下一頁</a>";

$str="總共{$pagePage}頁/當前是第{$page}頁";

for($i=1;$i<=$totalPage;$i++){

//當前頁無鏈接

if($page==$i){

$p.="[{$i}]";

}else{

$p.="<a href='{$url}?page={$i}{$where}'>[{$i}]</a>";

}

}

$pageStr = $str.$sep . $index .$sep. $prev.$sep . $p.$sep . $next.$sep . $last;

return $pageStr;

}

admin.inc.php

*分頁

*/

function getAdminByPage($page,$pageSize=2){

$sql="select * from sam_admin";

global $totalRows;

$totalRows = getResultNum($sql);

global $totalPage;

$totalPage=ceil($totalRows/$pageSize);

if($page<1||$page==null||!is_numeric($page)){

$page=1;

}

if($page >= $totalPage)$page=$totalPage;

$offset =($page-1)*$pageSize;

$sql = "select * from sam_admin limit {$offset},{$pageSize}";

$rows=fetchAll($sql);

return $rows;

}

listAdmin

$pageSize=2;

$rows = getAdminByPage($page,$pageSize);

$page=$_REQUEST['page']?(int)$_REQUEST['page']:1;

//$rows = getAllAdmin();

if(!$rows){

alertMes("沒有管理員,請添加!","addAdmin.php");

exit;

}

?>

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>-.-</title>

<link rel="stylesheet" href="styles/backstage.css">

</head>

<body>

<div class="details">

<div class="details_operation clearfix">

<div class="bui_select">

<input type="button" value="添&nbsp;&nbsp;加" class="add" ?onclick="addAdmin()">

</div>

</div>

<!--表格-->

<table class="table" cellspacing="0" cellpadding="0">

<thead>

<tr>

? ? ? ? ? ? ? ?<th width="15%">編號</th>

? ? ? ? ? ? ? ?<th width="30%">管理員名稱</th>

? ? ? ? ? ? ? ?<th width="30%">郵箱</th>

? ? ? ? ? ? ? ?<th>操作</th>

? ? ? ? ? ? </tr>

? ? ? ? ?</thead>

<tbody>

<?php foreach($rows as $row):?>

? <tr>

?<!--這里的id和for里面的c1 需要循環出來-->

?<td><input type="checkbox" id="c1" class="check"><label for="c1" class="label"><?php echo $row['id'];?></label></td>

?<td><?php echo $row['username'];?></td>

?<td><?php echo $row['email'];?></td>

?<td align="center">

<input type="button" value="修改" class="btn" onclick="editAdmin(<?php echo $row['id'];?>)">

<input type="button" value="刪除" class="btn" onclick="delAdmin(<?php echo $row['id'];?>)">

?</td>

? </tr>

<?php endforeach;?>

<?php if($totalRows>$pageSize):?>

<tr>

<td colspan="4"><?php echo showPage($page,$totalPage);?></td>

</tr>

<?php endif;?>

</tbody>

</table>

</div>

</body>

</html>

<script type="text/javascript">

function editAdmin(id){

window.location="editAdmin.php?id="+id;

}

function addAdmin(){

window.location="addAdmin.php";

}

function delAdmin(id){

if(window.confirm("您確定要刪除嗎?刪除之后不可以恢復哦!")){

window.location="doAdminAction.php?act=delAdmin&id="+id;

}

}

</script>



正在回答

1 回答

怎么會沒看出哪點有錯,我復制我的代碼吧,我是直接直接封進去的,往里面傳數據表就行了。分頁封裝那個函數沒錯,那就是封裝那個條件時出的問題了。我直接復制我封裝的條件函數吧:

function getAdminByPage($pageSize=2,$table){? ?
??? $sql="select * from {$table}";
??? global $totalPage,$totalRows,$page;
??? $totalRows=getResultNum($sql);?? ?
??? $totalPage=ceil($totalRows/$pageSize);
??? $page=$_REQUEST['page']?(int)$_REQUEST['page']:1;
??? if ($page<1||$page==null||!is_numeric($page)){
??????? $page=1;
??? }
??? if ($page>=$totalPage){
??????? $page=$totalPage;
??? }
??? $offset=($page-1)*$pageSize;
??? $sql="select * from {$table} order by id asc limit {$offset},{$pageSize}";
??? $res=fetchAll($sql);
??? return $res;
}

前面頁面調用時間的代碼:

<?php
require_once '../include.php';
$pageSize=2;
$table="imooc_cate";
$res=getAdminByPage($pageSize,$table);
if (!$res){
??? alterMes("沒有管理員,請先添加","addAdmin.php");
??? exit();
}
?>

這里你用的是$rows?? 我用的是$res? 你記得改一下。

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
手把手教你實現電商網站后臺開發
  • 參與學習       117251    人
  • 解答問題       2101    個

手把手教你用PHP搭建電子商務平臺,由淺入深教你搭建電商系統

進入課程

我的分頁封裝后,點擊上下一頁,首尾都不管用??!

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號