<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                如果某個類目下有很多條記錄,我們不可能一下子全部展現給用戶,第一:用戶看不完,第二:一次性全部加載性能太差。所以就需要用到翻頁技術,用戶看哪兒加載哪兒,這個和javascrip結合ajaxt實現瀑布流懶加載有點類似。 下面是我自己寫的php分頁代碼,php代碼和html代碼放在了一個頁面,僅供測試使用,如果你想用在項目里邊,可以把對應的類單獨放在某個php文件中,然后前端頁面include引用即可。 最后做完的截圖如下: ![](https://box.kancloud.cn/28a1540db9954e7a1da7ef5fa5b0dacd_363x204.jpg =500x400) 代碼如下: <?php header('content-type:text/html;charset="utf-8"'); class Teacher{ private $current;//當前頁 private $totalRecord;//總共查詢到的記錄數 private $pageLen = 3;//每頁顯示的記錄數 private $totalPage;//總頁數 private $url;//網址 private $startRecord;//從第幾條記錄開始查詢 private $pdo;//數據庫信息 public function __construct(){ $this->pdo = $this->getDb(); $query = 'select * from teacher'; $result = $this->pdo->query($query); $res = $result->fetchAll(PDO::FETCH_ASSOC); $this->current = $_GET['page'] ? $_GET['page'] : 1; $this->url = $this->getUrl(); $this->totalRecord = count($res); $this->totalPage = ceil($this->totalRecord/$this->pageLen); } //連接數據庫 private function getDb(){ $pdo = new PDO('mysql:host=localhost;dbname=edu','edu','edu'); return $pdo; } //提取保留url地址中除page之外的其他參數 private function getUrl(){ $url = parse_url($_SERVER['REQUEST_URI']); $query = $url['query']; parse_str($query,$arry); unset($arry['page']); $newQuery = http_build_query($arry); return $url['path'].'?'.$newQuery.'&page='; } //首頁 private function first(){ if($this->current>1){ return '<a href="'.$this->url.'1'.'">首頁</a>'; } } //上一頁 private function pre(){ if($this->current<=$this->totalPage){ return '<a href="'.$this->url.($this->current-1).'">上一頁</a>'; } } //下一頁 private function next(){ if($this->current<$this->totalPage){ return '<a href="'.$this->url.($this->current+1).'">下一頁</a>'; } } //末頁 private function end(){ if($this->current<$this->totalPage){ return '<a href="'.$this->url.($this->totalPage).'">末頁</a>'; } } //獲取表格內容 public function getContent(){ $this->startRecord = 2*$this->current-2; $query = 'select * from teacher where id limit '.$this->startRecord.','.$this->pageLen; $pageResult = $this->pdo->query($query); $pageRes = $pageResult->fetchAll(PDO::FETCH_ASSOC); unset($this->pdo); return $pageRes; } //分頁樣式 public function pageStyle(){ return '共有'.$this->totalPage.'頁&nbsp;&nbsp;&nbsp;'.$this->first().$this->pre().$this->next().$this->end(); } } $teacher = new Teacher(); $card = $teacher->getContent(); ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title></title> <meta name="keywords" content="" /> <meta name="description" content="" /> <style type="text/css"> *{margin:0px;padding:0px;} body{font-size:12px;} .teacherInfo{margin:100px auto 100px 100px;} .teacherInfo .pageList{margin-top:10px;} a{text-decoration:none;margin-right:10px;} a:hover{color:#f00;} td{padding:0px 10px;height:30px;line-height:30px;border:1px solid #ccc;} </style> </head> <body> <div class="teacherInfo"> <table cellpadding="0" cellspacing="0"> <thead> <tr> <td>ID</td> <td>姓名</td> <td>年齡</td> <td>性別</td> </tr> </thead> <tbody> <?php $len = count($card); for($i=0;$i<$len;$i++){ echo '<tr><td>'.$card[$i]["id"].'</td><td>'.$card[$i]["tname"].'</td><td>'.$card[$i]["tage"].'</td><td>'.$card[$i]["tsex"].'</td></tr>'; } ?> </tbody> </table> <div class="pageList"> <?php echo $teacher->pageStyle(); ?> </div> </div> </body> </html> 數據庫中的記錄截圖如下: ![](https://box.kancloud.cn/92c017bfa27335168a6c2f8c1f173a39_374x282.jpg =500x600)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看