Use PHP + MYSQL to achieve classification + pagination in the forum

Source: Internet
Author: User
<?
/* Table structure for storing posts ------------------------------------------------------
Create table bbsrow (
Bbsrow_id int (6) not null auto_increment, // ID of the subscriber
Bbsrow_auth varchar (20) not null, // Post author
Bbsrow_parentid int (6), // ID of the parent ID of the post, which is blank if the first post is sent
Bbsrow_title varchar (200) not null, // post subtitle
Bbsrow_returncount int (3), // number of replies to the Post. It is null if no replies are posted.
Primary key (bbsrow_id)
);
-----------------------------------------------------------------------------*/
// Display the recursive function posted by the 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 "<ul> ";
While ($ myrow_child = mysql_fetch_row ($ result_top )){
Echo "<li> ";
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 blank, it indicates that there is a son Post and the son Post will continue to be displayed.
If ($ myrow_child [4]! = ''){
Showchildren ($ myrow_child [0]);
}
}
Echo "</ul> ";
}
//----------------------------------------------------------------------
// Connect to the database and put all the first posts in 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];

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.