第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

php寫(xiě)的分頁(yè)類,有不有什么建議?

php寫(xiě)的分頁(yè)類,有不有什么建議?

PHP
西蘭花偉大炮 2017-06-23 23:50:40
<?php header('content-type:text/html;charset=utf-8'); //php中header的總結(jié) class?Sep_page{ ????private?$page?=?3; ????private?$ip?=?'localhost',$db_name?=?'root',$db_pass?=?'199486',$db_table?=?null; ???? ???? ????public?function?__construct($config?=?array()){ ????????$this->page?=?$config['page']; ????????$this->ip?=?$config['ip']; ????????$this->db_name?=?$config['db_name']; ????????$this->db_pass?=?$config['db_pass']; ????????$this->db_table?=?$config['db_table']; ????} ????public?function?judge_page(){ ????????$page?=?$this->page; ???????? ????????$para?=?self::connect_mysqli();??//類中方法調(diào)用方法用self ????????//print_r($para['rows'][0]['id']); ????????$total_page?=?ceil($para['total']/10); ????????//得到總頁(yè)數(shù) ????????$p1?=?$page?-?1; ????????$p2?=?$page?+?1; ????????//上下頁(yè)的URL傳參 ????????$start?=?1; ????????$end?=?$total_page; ????????//初始化開(kāi)始,結(jié)束頁(yè) ????????$show_page?=?5; ????????//頁(yè)面顯示數(shù)字按鈕數(shù) ????????$offset_page?=?($show_page-1)/2; ????????//點(diǎn)擊按鈕左右按鈕的數(shù)量 ????????$page_banner?=?""; ????????//通過(guò)字符串拼接分頁(yè) ????????if($page?>?1){ ????????????$page_banner.=?"<li><a?href='".$_SERVER['PHP_SELF']."?id=1'>首頁(yè)</a></li>"; ????????????$page_banner.=?"<li><a?href='".$_SERVER['PHP_SELF']."?id=$p1'>上一頁(yè)</a></li>"; ????????} ????????//$_SERVER['PHP_SELF']???顯示當(dāng)前文件路徑 ????????//頁(yè)數(shù)大一1才顯示首頁(yè)和上一頁(yè)????judge/判斷 ????????if($total_page?>?$show_page){ ????????????//先判斷總頁(yè)數(shù)與顯示頁(yè)數(shù)的關(guān)系 ????????????if($page>$offset_page){ ????????????????//開(kāi)始的頁(yè)碼為頁(yè)數(shù)減去偏移量 ????????????????$start?=?$page?-?$offset_page; ????????????????$end?=?$total_page>$page+$offset_page?$page+$offset_page:$total_page; ????????????}else{ ????????????????$start?=?1; ????????????????$end?=?$show_page; ????????????} ????????????if($page+$offset_page>$total_page){ ????????????????$start?=?$start?-?($page?+?$offset_page?-?$total_page); ????????????} ????????} ????????for($i?=?$start;$i<=$end;$i++){ ????????????$page_banner?.="<li><a?href='".$_SERVER['PHP_SELF']."?id=$i'>$i</a></li>"; ????????} ????????if($page?<?$total_page){ ????????????$page_banner.="<li><a?href='".$_SERVER['PHP_SELF']."?id=$p2'>下一頁(yè)</a></li>"; ????????????$page_banner.=?"<li><a?href='".$_SERVER['PHP_SELF']."?id=$total_page'>尾頁(yè)</a></li>"; ????????}//頁(yè)數(shù)小于總頁(yè)數(shù)才顯示尾頁(yè)和下一頁(yè) ????????$page_banner.="<li>共{$total_page}頁(yè)</li>"; ????????$response?=?array('rows'?=>?$para['rows'],?'$string'=>$page_banner); ????????return?$response; ????} ????private?function?connect_mysqli(){ ???????? ????????$mysqli?=?new?mysqli($this->ip,$this->db_name,$this->db_pass,$this->db_table); ????????$sql?=?"SELECT?*?FROM?page?LIMIT?".(($this->page-1)*10).",10"; ????????//var_dump($this->mysqli); ????????//echo?"<hr>"; ????????//echo?$sql; ???????? ????????$mysqli_result?=?$mysqli->query($sql); ????????//var_dump($mysqli_result); ????????while($row?=?$mysqli_result->fetch_assoc()){ ????????????$rows[]?=?$row; ????????} ????????//var_dump($row); ????????//var_dump($rows); ????????$sql_count?=?"SELECT?COUNT(*)?FROM?page"; ????????//得到數(shù)據(jù)表數(shù)據(jù)總數(shù) ????????$mysqli_result?=?$mysqli->query($sql_count); ????????$row?=?$mysqli_result->fetch_array(); ????????//print_r($row);??//$row返回的是一個(gè)關(guān)聯(lián)加索引的數(shù)組,第一項(xiàng)就存儲(chǔ)的數(shù)據(jù)總數(shù),因此需要$row[0]來(lái)取 ????????$total?=?$row[0]; ????????$return?=?array('rows'?=>?$rows,?'total'=>$total); ????????return?$return; ????} } $config?=?$arrayName?=?array('page'=>$_GET['id'],'ip'=>?'localhost','db_name'=>'root','db_pass'=>'199486','db_table'=>'article'); $weidapao?=?new?Sep_page($config); //print_r($rows?=?$weidapao->judge_page()); $rows?=?$weidapao->judge_page(); $number?=?$rows['rows'] //print_r($weidapao->connect_mysqli()); ?> <!DOCTYPE?html> <html?lang="en"> <head> ????<meta?charset="UTF-8"> ????<title></title> ????<link?rel="stylesheet"? ??????????> </head> <body> <table?class="table?table-striped"> ????<?php?foreach($number?as?$row):??> ????<tr> ????????<td><?php?echo?$row['id'];??></td> ????????<td><?php?echo?$row['username'];??></td> ????</tr> ????<?php?endforeach;?> </table> <ul?class="pagination"> ????<?php?echo?$rows['$string'];?> </ul> </body> </html>測(cè)試是沒(méi)有問(wèn)題的,但是我覺(jué)得肯定有細(xì)節(jié)問(wèn)題需要改進(jìn),希望有人能提出怎么改,為什么,具體代碼,謝謝
查看完整描述

1 回答

?
書(shū)旅

TA貢獻(xiàn)238條經(jīng)驗(yàn) 獲得超101個(gè)贊

我覺(jué)得寫(xiě)的挺好啊,比我的好

查看完整回答
反對(duì) 回復(fù) 2017-06-24
  • 1 回答
  • 0 關(guān)注
  • 1612 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)