PHP分面代码收集,我将从中取出有特色与众不同的,代码具体给高分。欢迎大家来投稿。
---------------------------------------------------------------
自己写的PHP分页代码,使用mysql数据库
count = $count; $this->page = $page; $this->pageSize = $pageSize; $this->pageSegSize = $pageSegSize; } /** Update the page data */ function update() { //-->check value: count, pageSize if ($this->count <= 0) $this->count = 0; if ($this->pageSize > $this->count) $this->pageSize = $this->count; if ($this->pageSize < 1) $this->pageSize = 1; $this->pageCount = ceil($this->count / $this->pageSize); //-->check value: page if ($this->page > $this->pageCount) $this->page = $this->pageCount; if ($this->page < 1) $this->page = 1; //<\-- //-->check value: pageSegSize if ($this->pageSegSize > $this->pageCount) $this->pageSegSize = $this->pageCount; if ($this->pageSegSize < 1) $this->pageSegSize = 1; //<\-- $this->scopeStart = ($this->page - 1) * $this->pageSize; $this->scopeEnd = $this->scopeStart + $this->pageSize - 1; if ($this->scopeEnd >= $this->count) $this->scopeEnd = $this->count; $this->pageScopeStart = 1; $this->pageScopeEnd = $this->pageCount; if ($this->prevNString != '' ¦ ¦ $this->nextNString != ''){ //use page segment $this->pageSeg = 1; $this->pageScopeStart = (ceil($this->page / $this->pageSegSize) - 1) * $this->pageSegSize + 1; $this->pageScopeEnd = $this->pageScopeStart + $this->pageSegSize - 1; if ($this->pageScopeEnd > $this->pageCount) $this->pageScopeEnd = $this->pageCount; } } \--------------------------------------------------------------- if ($this->firstString != '') { //set FIRST button (if firstString exists) if ($this->page == 1 ¦ ¦ $this->pageCount < 1) { $this->navBar = "{$this->firstString} {$this->navBar}"; } else { $href = sprintf($this->linkPattern1, 1); $this->navBar = " ``` {$this->firstString} ``` {$this->navBar}"; } } if ($this->lastString != '') { //set LAST button (if lastString exists) if ($this->page >= $this->pageCount) { $this->navBar = "{$this->navBar}{$this->lastString} "; } else { $href = sprintf($this->linkPattern1, $this->pageCount); $this->navBar = "{$this->navBar} ``` {$this->lastString} ``` "; } } return $this->navBar; } function setLinkPatterns($linkPattern1, $linkPattern2) { $this->linkPattern1 = $linkPattern1; $this->linkPattern2 = $linkPattern2; } function setNavString($firstString, $prevNString, $prevString, $nextString, $nextNString, $lastString) { $this->firstString = $firstString; $this->prevNString = $prevNString; $this->prevString = $prevString; $this->nextString = $nextString; $this->nextNString = $nextNString; $this->lastString = $lastString; } function setPageSegSize($pageSegSize) { $this->pageSegSize = $pageSegSize; } function setPageSize($pageSize) { $this->pageSize = $pageSize; } function setPage($page) { $this->page = $page; } function setCount($count) { $this->count = $count; } } class DBPager extends Pager { var $con = 0; //integer : connection id var $sql = ''; //string : sql clause var $list = array(); //array : returned result of db query function DBPager($con = 0, $sql = '', $page = 1) { $this->con = $con; $this->sql = $sql; $this->page = $page; } function setCount($count) { } function update() { $pattern = "select(.*)from"; $replace = "select count(*) from"; $sqlCount = eregi_replace($pattern, $replace, $this->sql); $result = mysql_query($sqlCount, $this->con); $row = mysql_fetch_row($result); $this->count = $row[0]; parent::update(); $this->sql .= sprintf(" limit %d, %d", $this->scopeStart, $this->pageSize); $result = mysql_query($this->sql, $this->con); $i = 0; while ($row = mysql_fetch_row($result)) { $this->list[$i] = $row; $i++; } } function getList() { return $this->list; } } \--------------------------------------------------------------- function getCount() { return $this->count; } function getPage() { return $this->page; } function getPageSize() { return $this->pageSize; } function getPageSegSize() { return $this->pageSegSize; } function getPageCount() { return $this->pageCount; } function getScopeStart() { return $this->scopeStart; } function getScopeEnd() { return $this->scopeEnd; } function getPageScopeStart() { return $this->pageScopeStart; } function getPageScopeEnd() { return $this->pageScopeEnd; } function getNavBar() { if ($this->linkPattern1 == '' ¦ ¦ $this->linkPattern2 == '') //no navigator bar return ''; if ($this->navBar == '') { //start calculating basic navigator bar $s = ''; for ($i = $this->pageScopeStart; $i <= $this->pageScopeEnd; $i++) { $t = sprintf($this->linkPattern2, $i); if ($this->page == $i) {