php数据库改分页类 php mysql 分页( 五 )


}
return $html;
}
private function go_next() {
$html="";
if ($this-page==$this-total_pages) {
$html.="nbsp;{$this-config['next']}nbsp;";
}else{
$html.="nbsp;a href='https://www.04ip.com/post/{$this-uri}page={$this-page}+1'{$this-config['next']}/anbsp;";
}
return $html;
}
private function go_last() {
$html="";
if ($this-page==$this-total_pages) {
$html.="nbsp;{$this-config['last']}nbsp;";
}else{
$html.="nbsp;a href='https://www.04ip.com/post/{$this-uri}page={$this-total_pages}'{$this-config['last']}/anbsp;";
}
return $html;
}
private function go_page() {
return 'nbsp;input type="text" onkeydown="javascript:if(event.keyCode==13){var page=(this.value'.$this-total_pages.')?'.$this-total_pages.':this.value;location=\''.$this-uri.'page=\'+page+\'\'}" value="'.$this-page.'" style="width:25px;" /input type="button" onclick="javascript:var page=(this.previousSibling.value'.$this-total_pages.')?'.$this-total_pages.':this.previousSibling.value;location=\''.$this-uri.'page=\'+page+\'\'" value="https://www.04ip.com/post/GO" /nbsp;';
}
private function page_list() {
$link_page="";
$i_num=floor($this-list_length/2);
for ($i = $i_num; $i = 1; $i--) {
$page=$this-page-$i;
if ($page1) {
continue;
}else{
$link_page.="nbsp;a href='https://www.04ip.com/post/{$this-uri}page={$page}'{$page}/anbsp;";
}
}
$link_page.="nbsp;{$this-page}nbsp;";
for ($i = 1; $i$i_num; $i++) {
$page=$this-page+$i;
if ($page=$this-total_pages) {
$link_page.="nbsp;a href='https://www.04ip.com/post/{$this-uri}page={$page}'{$page}/anbsp;";
}else{
break;
}
}
return $link_page;
}
public function out_page($display=array(0,1,2,3,4,5,6,7,8)) {
$display_html='';
$html[0]="nbsp;共有b{$this-total_rows}/b{$this-config['header']}nbsp;";
$html[1]="nbsp;每页显示b".($this-end_page()-$this-start_page()+1)."/b条,本页显示从b{$this-start_page()}/b--b{$this-end_page()}/b{$this-config['header']}nbsp;";
$html[2]="nbsp;b{$this-page}/b/b{$this-total_pages}/b页nbsp;";
$html[3]=$this-go_first();
$html[4]=$this-go_prev();
$html[5]=$this-page_list();
$html[6]=$this-go_next();
$html[7]=$this-go_last();
$html[8]=$this-go_page();
foreach ($display as $index){
$display_html.=$html[$index];
}
return $display_html;
}
}
?
怎么做php数据库调取数据分页显示,要php的?php
include("connection.php");
$perNumber=10; //每页显示的记录数
$page=$_GET['page']; //获得当前的页面值
$count=mysql_query("select count(*) from user"); //获得记录总数
$rs=mysql_fetch_array($count);
$totalNumber=$rs[0];
$totalPage=ceil($totalNumber/$perNumber); //计算出总页数
if (!isset($page)) {
$page=1;
} //如果没有值,则赋值1
$startCount=($page-1)*$perNumber; //分页开始,根据此方法计算出开始的记录
$result=mysql_query("select * from user limit $startCount,$perNumber"); //根据前面的计算出开始的记录和记录数
while ($row=mysql_fetch_array($result)) {
echo "user_id:".$row[0]."br";
echo "username:".$row[1]."br"; //显示数据库的内容
}
if ($page != 1) { //页数不等于1
?
a href="https://www.04ip.com/post/fenye.php?page=?php echo $page - 1;?"上一页/a !--显示上一页--
?php
}
for ($i=1;$i=$totalPage;$i++) {//循环显示出页面
?
a href="https://www.04ip.com/post/fenye.php?page=?php echo $i;?"?php echo $i ;?/a
?php
}
if ($page$totalPage) { //如果page小于总页数,显示下一页链接
?
a href="https://www.04ip.com/post/fenye.php?page=?php echo $page + 1;?"下一页/a
?php
}

推荐阅读