今天在工作之余寫的一段PHP分頁處理腳本,歡迎拍磚!!! 顯示頁面 index.php
'; //如果遍歷完$arr數組裡的所以元素,即$i($i從0開始)等於數組的元素個數減一,則跳出2層循環(for循環和foreach循環) if ($i==(count($arr)-1)) break 2; } } $RowCount=getRowCount($connectmysql);//一共有多少條記錄 $PageCount=ceil($RowCount/$PageSize);//共有幾頁,ceil()函數進一取整 echo '帖子統計:'.$RowCount.'條'.' '.'共有'.$PageCount.'頁 '; //當為第一頁時不輸出“上一頁” if ($CurrentPageID != 1){ echo "上一頁"; } //向前跳頁 if ($CurrentPageID > 2){ echo " <<< "; } //輸出詳細的頁數,如:【1】 for ($j=1;$j<=$PageCount;$j++){ echo "[$j]"; } //向後跳頁 if ($CurrentPageID <= ($PageCount-2)){ echo " >>> "; } //當為最後一頁時不輸出“下一頁” if ($CurrentPageID != $PageCount){ echo "下一頁"; } $connectmysql->closeConn(); }
getRowsArray($sql); return $arr1; } //該函數用來查詢數據庫的表的行數 function getRowCount($connectmysql){ $sql="select * from db_content"; $num=$connectmysql->getRowsNum($sql); return $num; }
conn=mysql_connect($this->host,$this->username,$this->password); @mysql_select_db($this->dbname,$this->conn); mysql_query('set names utf-8'); } //查詢結果 function getResult($sql){ if ($this->conn==''){ $this->conndb(); } $this->result=mysql_query($sql,$this->conn); } //返回查詢的記錄數 function getRowsNum($sql){ $this->getResult($sql); $num_rows=mysql_num_rows($this->result); if (mysql_errno()==0){ return $num_rows; }else { return ''; } } //將結果輸出為一個單條記錄數組並返回 function getArray($sql){ $this->getResult($sql); if (mysql_errno()==0){ $this->resultArray=mysql_fetch_array($this->result,MYSQL_ASSOC);//得到關聯數組 return $this->resultArray; }else { return ''; } } //返回一個含有多條記錄的二維數組 function getRowsArray($sql){ $this->getResult($sql); if (mysql_errno()==0){ while ($row=mysql_fetch_array($this->result,MYSQL_ASSOC)){ $this->rowsArray[]=$row; } return $this->rowsArray; //print_r($this->rowsArray);exit; }else { return ''; } } //更新、添加、刪除 function uidresult($sql){ if ($this->conn==''){ $this->conndb(); } //echo $sql; //exit; @mysql_query($sql); $this->rowsNum=@mysql_affected_rows(); if (mysql_errno()==0){ return $this->rowsNum; }else { return ''; } } //釋放結果集 function freeResult(){ mysql_free_result($this->result); $this->rowsNum=0; $this->rowsArray=''; $this->resultArray=''; } //關閉數據庫 function closeConn(){ $this->freeResult(); mysql_close($this->conn); $this->conn=''; } }