首页 » PHP » 阅读文章
从UCHOME提取的分页函数
标签:PHP
<?php // 总数, 第页显示数, 当前页码, 基础链接 function multi($num, $perpage, $curpage, $mpurl) { global $_SCONFIG; $page = 5; $multipage = ”; $mpurl .= strpos($mpurl, ‘?’)!==false ? ‘&’ : ‘?’; $realpages = 1; if($num > $perpage) { $offset = 2; $realpages = @ceil($num / $perpage); $pages = $_SCONFIG[‘maxpage’] && $_SCONFIG[‘maxpage’] < $realpages ? $_SCONFIG[‘maxpage’] : $realpages; if($page > $pages) { $from = 1; $to = $pages; } else { $from = $curpage – $offset; $to = $from + $page – 1; if($from < 1) { $to = $curpage + 1 – $from; $from = 1; if($to – $from < $page) { $to = $page; } } elseif($to > $pages) { $from = $pages – $page + 1; $to = $pages; } } $multipage = ($curpage – $offset > 1 && $pages > $page ? ‘<a href=”‘.$mpurl.’page=1″>首页</a>’ : ‘<a href=”‘.$mpurl.’page=1″>首页</a>’). (‘<a href=”‘.$mpurl.’page=’.($curpage – 1).'”>上一页</a>’); for($i = $from; $i <= $to; $i++) { $multipage .= $i == $curpage ? ‘<strong>’.$i.'</strong>’ : ‘<a href=”‘.$mpurl.’page=’.$i.'”>’.$i.'</a>’; } $multipage .= (‘<a href=”‘.$mpurl.’page=’.($curpage + 1).'”>下一页</a>’). (0 && $to < $pages ? ‘<a href=”‘.$mpurl.’page=’.$pages.'”>末页</a>’ : ‘<a href=”‘.$mpurl.’page=’.$pages.'”>末页</a>’); $multipage = $multipage ? ‘<div>’.'<em> 共’.$num.’个 </em>’.$multipage.'</div>’ : ‘<div>’.'<em> ’.$num.’ </em>’.$multipage.'</div>’; } else{ // 只有一页也显示分页 $multipage = ‘<div><em> 共’.$num.’个 </em><a href=”#”>首页</a><a href=”#”>上一页</a><strong>1</strong><a href=”#”>下一页</a><a href=”#”>末页</a></div>’; } $maxpage = $realpages; return $multipage; }?> 调用方法 // 初始化 // 查询 |
评论 共0条 (RSS 2.0) 发表评论