Use PHP + MYSQL to achieve classification in the forum + display by page _ MySQL

Source: Internet
Author: User
* The table structure that stores the posts: createtablebbsrow (bbsrow_idint (6) comment, the ID of the post: bbsrow_authvarchar (20) notnull. The Post author: bbsrow_parentidint (6, for example, the table structure of the first post/* store the sub-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"
    N ";
    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]. "n ";
    // 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"
";
}
//----------------------------------------------------------------------

// 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];
$ I ++;
}
Mysql_free_result ($ result );
//----------------------------------------------------------------------

// Start to build the pagination display ------------------------------------------------------

If ($ currentpage! = ""){
$ Page = $ currentpage;
}
Else {
$ Page = 0;
}

$ Pagesize = 10; // Number of first posts per page!
$ Start = $ page * $ pagesize;
$ End = $ start + $ pagesize;
If ($ end> $ I) $ end = $ I;
$ Totalpage = $ I/$ pagesize;


$ Info = "total ". $ I. "Records, points ". ceil ($ totalpage ). "page, which is the current ". ($ page + 1 ). "/". ceil ($ totalpage ). "page
N ";
Echo $ info;

If ($ page> 0) $ pagestr = "previous page ";
$ Pagestr = $ pagestr. "[No ";

For ($ I = 0; $ I <$ totalpage; $ I ++ ){
If ($ I! = $ Page ){
$ Pagestr = $ pagestr. "". ($ I + 1 )."";
}
Else {
$ Pagestr = $ pagestr. "". ($ I + 1 )."";
}
}

$ Pagestr = $ pagestr. "Page]";

If ($ page <$ totalpage-1) $ pagestr = $ pagestr. "Next page

N ";

Echo $ pagestr;
//----------------------------------------------------------------------

// Start grading display ----------------------------------------------------------

Echo"

    N ";
    For ($ I = $ start; $ I <$ end; $ I ++ ){
    Echo"
  • N ";
    Echo $ mainrow [$ I] [0];
    Echo $ mainrow [$ I] [1];
    Echo $ mainrow [$ I] [2];
    Echo $ mainrow [$ I] [3];
    Echo $ mainrow [$ I] [4]. "n ";
    // 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 ($ mainrow [$ I] [4]! = ''){
    Showchildren ($ mainrow [$ I] [0]);
    }
    }
    Echo"
N ";
// ------------------------------------------------------------------------?>

Original Author: unknown
Source: chinaasp

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.