search
Homephp教程PHP源码php mysql 分页代码与分页原理详解

本文章提供这一款php mysql 分页代码与分页代码是一款从创建数据库与查询数据到把数据进行分页,比较适合于php初学者,并且这款分页代码实用简单容易。

<script>ec(2);</script>


/*存放贴子的表结构------------------------------------------------------

 代码如下 复制代码
create table bbsrow(
bbsrow_id int(6) not null auto_increment, //贴子ID号
bbsrow_auth varchar(20) not null, //贴子作者
bbsrow_parentid int(6), //贴子的父亲贴子ID号,如为首发贴则为空
bbsrow_title varchar(200) not null, //贴子标题
bbsrow_returncount int(3), //贴子的回复贴数,如果没有回贴则为空
primary key (bbsrow_id)


);
-----------------------------------------------------------------------------*/


//显示儿子贴的递归函数--------------------------------------------------

 代码如下 复制代码
function showchildren($parent_id){
global $connect_id;
$query="select * from bbsrow where bbsrow_parentid='" . $parent_id . "'";
$result_top=mysql_query($query,$connect_id);
echo "
    ";
    while($myrow_child=mysql_fetch_row($result_top)){
    echo "
  • ";
    echo $myrow_child[0];
    echo $myrow_child[1];
    echo $myrow_child[2];
    echo $myrow_child[3];
    echo $myrow_child[4] . " ";
    //如果回复贴数不为空,则表示有儿子贴,继续显示儿子贴
    if($myrow_child[4]!=''){
    showchildren($myrow_child[0]);
    }
    }
    echo "
";
}

//----------------------------------------------------------------------

//连接数据库并将所有首发贴放到$mainrow数组里----------------------------

 代码如下 复制代码

$connect_id=mysql_connect("localhost","test","test") or die("无法连接数据库");
mysql_select_db("bbs") or die("无法选择数据库");
$query="select * from bbsrow where bbsrow_parentid=''";
$result=mysql_query($query,$connect_id);

$i=0;
while($myrow=mysql_fetch_row($result)) {
$mainrow[$i][0]=$myrow[0];
$mainrow[$i][1]=$myrow[1];
$mainrow[$i][2]=$myrow[2];
$mainrow[$i][3]=$myrow[3];
$mainrow[$i][4]=$myrow[4];
$i++;
}
mysql_free_result($result);
//----------------------------------------------------------------------

//开始构建分页显示------------------------------------------------------

if($currentpage!=""){
$page=$currentpage;
}
else{
$page=0;
}

$pagesize=10;//每页显示的首发贴数!
$start=$page*$pagesize;
$end=$start+$pagesize;
if($end>$i) $end=$i;
$totalpage=$i/$pagesize;


$info=" 共有" . $i . "条纪录,分" . ceil($totalpage) . "页,当前为第" . ($page+1) . "/" . ceil($totalpage) . "页
";
echo $info;

if($page>0) $pagestr="上一页";
$pagestr=$pagestr . " [第 ";

for($i=0;$i if($i!=$page){
$pagestr=$pagestr . " " . ($i+1) . " ";
}
else{
$pagestr=$pagestr . " " . ($i+1) . " ";
}
}

$pagestr=$pagestr . "页]";

if($page下一页

";

echo $pagestr;

//----------------------------------------------------------------------

//开始分级显示----------------------------------------------------------

 代码如下 复制代码
echo "
    ";
    for($i=$start;$i echo "
  • ";
    echo $mainrow[$i][0];
    echo $mainrow[$i][1];
    echo $mainrow[$i][2];
    echo $mainrow[$i][3];
    echo $mainrow[$i][4] . " ";
    //如果回复贴数不为空,则表示有儿子贴,继续显示儿子贴
    if($mainrow[$i][4]!=''){
    showchildren($mainrow[$i][0]);
    }
    }
    echo "
";

//----------------------------------------------------------------------?>

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor