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

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

為什么上一頁到第一頁之后還可以上一頁到-1??

<html>
??? <head>
??????? <meta http-equiv="Content-type" content="text/html;charset=utf-8">
??? </head>
??? <style>
??????? body{
??????????? font-size: 12px;font-family:verdana;width:100%;
??????? }
??????? div.page{
??????????? text-align: center;
??????? }
??????? div.content{
??????????? height:300px;
??????? }
??????? div.page a{
??????????? border:#ff3333 1pxsolid;text-decoration:none;padding: 2px 5px 2px 5px;margin: 2px;
??????? }
??????? div.page span.current{
??????????? border:#000099 1px solid;background-color:#000099;padding:1px 1px 1px 1px;margin:2px;
??????? }
??????? div.page span.disable{
??????????? border:#eee 1px solid;padding:1px 1px 1px 1px;margin:2px;color:#ddd;
??????? }
??????? div.page form{
??????????? display:inline;
??????? }
?????? </style>
??? <body>
<?php
?? ?/**1.傳入頁碼**/
?? ?$page = $_GET['p'];
?? ?/**2根據頁碼取出數據:PHP->mysql處理**/
?? ?$host = "localhost";
?? ?$username = "root";
?? ?$password = "root";
?? ?$db = "shop";
??????? $pageSize = 5;
??????? $showPage = 5;
??????????? //鏈接數據庫
?? ?$conn = mysql_connect($host,$username,$password);
?? ?if(!$conn){
?? ??? ?echo '數據庫連接失敗';
?? ??? ?exit;
?? ?}
??????????? //選擇要操作的數據庫
?? ?mysql_select_db($db);
??????????? //設置數據庫編碼格式
?? ?mysql_query("set names utf8");
??????????? //編寫SQL獲取分頁數據SELECT * FROM 表明 LIMIT 起始位置,顯示條數
?? ?$sql="select * from sw_goods limit ".($page-1)*$pageSize.",$pageSize";
??????????? //把sql語句傳送到數據庫
?? ?$result = mysql_query($sql);
????????? // var_dump($result);
??????? //處理我們的數據
??????? echo "<div class=''content>";
??????? echo'<table border=1 cellspacing=0 width=40% align=center>';
??????? echo '<tr><td>ID</td><td>NAME</td></tr>';
?? ?while($row = mysql_fetch_assoc($result)){
??????????? echo '<tr>';
??????????? echo "<td>{$row['goods_id']}</td>";
??????????? echo "<td>{$row['goods_name']}</td>";
?????????? ?
??????????? echo '</tr>';
??????? }?? ?
???????? echo'</table>'; ?
???????? echo '</div>';
??????? //? 釋放結果集,關閉連接???? ?
??????? mysql_free_result($result);
??????? //獲取數據庫總數
??????? $total_sql = "SELECT COUNT(*)FROM sw_goods";
??????? $total_result = mysql_fetch_array(mysql_query($total_sql));
??????? $total = $total_result[0];
??????? //計算頁數
??????? $total_pages = ceil($total/$pageSize);
??????? //mysql_close($conn);
?? ?/**3顯示數據+分頁條**/
??????? $page_banner = "<div class='page'>";
??????? //計算偏移量
??????? $pageoffset = ($showPage-1)/2;
??????? if($page > 1){
??????????? $page_banner .= "<a href= '".$_SERVER['PHP_SELF']."?p=1'><首頁</a>";
??????????? $page_banner .= "<a href= '".$_SERVER['PHP_SELF']."?p=".($page-1)."'>上一頁</a>";
??????? }else{
????????? $page_banner.=? "<span class='disable'>首頁</a></span>";
????????? $page_banner.=? "<span class='disable'>上一頁</a></span>";
??????? }
??????? //初始化數據
??????? $start = 1;
??????? $end = $total_pages;
??????? if($total_pages > $showPage){
??????????? if($page > $pageoffset + 1){
??????????????? $page_banner .= "...";
??????????? }
??????? }
??????? if($page < $pageoffset){
??????????? $start = $page - $pageoffset;
??????????? $end = $total_pages > $page+$pageoffset?$page+$pageoffset:$total_pages;
??????? }else{
??????????? $start = 1;
??????????? $end = $total_pages > $showPage?$showPage:$total_pages;
??????? }
??????? if($page+$pageoffset>$total_pages){
??????????? $start = $start-($page + $pageoffset - $end);
??????? }
??????? for($i = $start;$i<=$end;$i++){
??????????? if($page == $i){
??????????????? $page_banner .= "<span class='current'>{$i}</span>";
??????????? }else{
????????? $page_banner .= "<a href='".$_SERVER['PHP_SELF']."?p=".$i."'>{$i}</a>"; ?
??????? }
??????? }
??????? //尾部省略
??????? if($total_pages>$showPage && $total_pages>$page + $pageoffset){
??????????? $page_banner .= "...";
??????? }
??????? if($page < $total_pages){
?????????? $page_banner .= "<a href='".$_SERVER['PHP_SELF']."?p=".($page+1)."'>下一頁</a>";
?????????? $page_banner .= "<a href= '".$_SERVER['PHP_SELF']."?p=".($total_pages)."'>尾頁></a>";
??????? }else{
?????????? $page_banner.=? "<span class='disable'>下一頁</a></span>";
?????????? $page_banner.=? "<span class='disable'>尾頁</a></span>";
??????? }
????? ?
??????? $page_banner .="共{$total_pages}頁.";
??????? $page_banner .= "<form action='page.php' method='get'>";
??????? $page_banner .= "到第<input type='text' size='2' name='p'>頁";
??????? $page_banner .= "<input type='submit' value='確定'>";
??????? $page_banner .= "</form></div>";
??????? echo $page_banner;
?>
??? </body>
</html>?? ?


正在回答

舉報

0/150
提交
取消

為什么上一頁到第一頁之后還可以上一頁到-1??

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

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

幫助反饋 APP下載

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

公眾號

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