这篇文章主要是用PHP函数实现数字与文字分页,具体实现步骤就不罗嗦了,直接上代码
function page($sql,$_size) {
//将里面的所有变量取出来,外部可以访问
global $_page,$_pagesize,$_pagenum,$_pageabsolute,$_num;
if (isset($_GET['page'])) {
$_page = $_GET['page'];
if (empty($_page) || $_page < 0 || !is_numeric($_page)) {
$_page = 1;
} else {
$_page = intval($_page);
}
} else {
$_page = 1;
}
$_pagesize = $_size;
$_num = _num_rows(_query($_sql));
if ($_num == 0) {
$_pageabsolute = 1;
} else {
$_pageabsolute = ceil($_num / $_pagesize);
}
if ($_page > $_pageabsolute) {
$_page = $_pageabsolute;
}
$_pagenum = ($_page - 1) * $_pagesize;
}
/**
function _paging($_type) {
global $_page,$_num;
if ($_type == 1) {
echo '<div id="page_num">';
echo '
- ';
- <a href="blog.php?page='.($i+1).'" class="selected">'.($i+1).' ';
- <a href="blog.php?page='.($i+1).'">'.($i+1).' ';
for ($i=0;$i<$_pageabsolute;$i++) {
if ($_page == ($i+1)) {
echo '
} else {
echo '
}
}
echo '
echo '
} elseif ($_type == 2) {
echo '<div id="page_text">';
echo '
- ';
- '.$_page.'/'.$_pageabsolute.'页 | ';
- 共有
'.$_num.'
个会员 | '; - 首页 | ';
- 上一页 | ';
- <a href="'.SCRIPT.'.php">首页 | ';
- <a href="'.SCRIPT.'.php?page='.($_page-1).'">上一页 | ';
- 下一页 | ';
- 尾页 ';
- <a href="'.SCRIPT.'.php?page='.($_page+1).'">下一页 | ';
- <a href="'.SCRIPT.'.php?page='.$_pageabsolute.'">尾页 ';
echo '
echo '
if ($_page == 1) {
echo '
echo '
} else {
echo '
echo '
}
if ($_page == $_pageabsolute) {
echo '
echo '
} else {
echo '
echo '
}
echo '
echo '