Use PHP + MYSQL to implement hierarchical + paging display in the forum_PHP tutorial

WBOY
Release: 2016-07-13 17:02:20
Original
848 people have browsed it

/*Table structure for storing posts--------------------------------------------- ------------------
create table bbsrow(
bbsrow_id int(6) not null auto_increment, //Post ID number
bbsrow_auth varchar(20 ) not null, //Post author
bbsrow_parentid int(6), //The post's father's post ID number, if it is the first post, it will be empty
bbsrow_title varchar(200) not null, //Post Subtitle
bbsrow_returncount int(3), //The number of replies to the post, if there is no reply, it will be empty
primary key (bbsrow_id)
);
------ -------------------------------------------------- --------------------*/
//Show the recursive function posted by my son----------------- ----------------------------------
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 the number of reply posts is not empty, it means there are son posts and continue to display son posts
    if($myrow_child[4]!=''){
    showchildren($myrow_child[0 ]);
    }
    }
    echo "
";
}
//------------------ -------------------------------------------------- --
//Connect to the database and put all first posts into the $mainrow array----------------------------
$connect_id=mysql_connect("localhost","test","test") or die("Unable to connect to database");
mysql_select_db("bbs") or die("Unable to select database");
$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];

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631062.htmlTechArticle? /*Table structure for storing posts--------------- --------------------------------------- create table bbsrow( bbsrow_id int(6) not null auto_increment, //Post ID number bbsrow_auth varchar(2...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template