| 注册老失败 |
 |
| 等级:大侠 |
| 权限:普通用户 |
| 积分:85 |
| 金钱:305 |
| 声望:170 |
| 经验:170 |
| 发帖数:170 |
| 注册:2008年10月16日 |
|
|
|
* 可利用这些信息编写自己的分页样式,不需另外计算 */ public function limit($resultId,$table,$fields,$primary,$page,$pageSize,$condition = '',$order = 1) { isset($this->pageMsg[$resultId][0]) || $this->pageMsg[$resultId][0] = $this->rowsTotal($table,$primary,$condition); $this->pageMsg[$resultId][1] = ceil($this->pageMsg[$resultId][0]/$pageSize); $page > $this->pageMsg[$resultId][1] && $page = $this->pageMsg[$resultId][1]; $this->pageMsg[$resultId][2] = $page == $this->pageMsg[$resultId][1] ? ($this->pageMsg[$resultId][0]-($page-1)*$pageSize) : $pageSize; $this->pageMsg[$resultId][3] = $page; $this->pageMsg[$resultId][4] = $pageSize; if ($this->cacheLifeTime && $page <= $this->cacheLimitMax) { $cachePath = $this->cachePath.$table.'_'.$page.'.php'; if (time() - @filemtime($cachePath) < $this->cacheLifeTime) { include $cachePath; $this->resultId[$resultId] = $dataCache; $this->offset[$resultId] = 0; return; } else $writeCache = true; } if ($order) { $mark = '<'; $min = 'min'; $order = ' order by '.$primary.' desc'; } else { $mark = '>'; $min = 'max'; $order = ''; } $sql = 'select top '.$this->pageMsg[$resultId][2].' '.$fields.' from '.$table; if (1 == $page) { $sql .= ($condition ? ' where '.$condition : '').$order; } else { $sql .= ' where '.$primary.$mark.'(select '.$min.'('.$primary.') from (select top '.($page-1)*$pageSize; $sql .= ' '.$primary.' from '.$table.$order.')) '.($condition ? 'and '.$condition : '').$order; } $this->query($sql,$resultId); $writeCache && $this->writeCache($cachePath,$resultId); } public function displayLimit($resultId,$linkHtml,$style = 2,$recordName = '条记录') { if (2 == $style) { echo '共 <strong>',$this->pageMsg[$resultId][0],'</strong> ',$recordName,' '; } echo '<a href=',str_replace('*','1',$linkHtml),'>首页</a> '; if (1 == $this->pageMsg[$resultId][3]) { echo '上一页 '; } else { echo '<a href=',strtr('*',$this->pageMsg[$resultId][3]-1,$linkHtml),'>上一页</a> '; } if ($this->pageMsg[$resultId][3] == $this->pageMsg[$resultId][1]) { echo '下一页'; } else { echo '<a href=',strtr('*',$this->pageMsg[$resultId][3]+1,$linkHtml),'>下一页</a>'; } echo ' <a href=',strtr('*',$this->pageMsg[$resultId][1],$linkHtml); echo '>尾页</a> 页次:<strong><font color=#ff0000>'; echo $this->pageMsg[$resultId][3],'</font>/',$this->pageMsg[$resultId][1],'</strong>页'; if (2 == $style) { echo ' <strong>',$this->pageMsg[$resultId]['e'],'</strong>',$recordName,'/页 转到'; echo ':<select name=page size=1 onchange="javascript:window.location='; echo 'this.options[this.selectedIndex].value;" style=font-size:12px;height=18px>'; for ($i=1;$i<=$this->pageMsg[$resultId][1];$i++) { echo '<option value=\'',strtr('*',$i,$linkHtml); echo $this->pageMsg[$resultId][3] == $i ? '\' selected ' : '\'','>第',$i,'页</option>'; } echo '</select>'; } } /** * 将查询结果输入缓存 * * 参数: * $cachePath 缓存路径 * $resultId 查询结果ID */ private function writeCache($cachePath,$resultId) { $cacheContent = ''; while ($rowArray = odbc_fetch_array($this->resultId[$resultId])) { $cacheContent .= '$dataCache[]=array('.$this->rowToStr($rowArray).');';
|
|
|
|
|
|