Implement the Forum tree structure and pagination using non-recursive methods !! (Painstaking efforts, huh, huh)

Source: Internet
Author: User
Now I will show you my practical results. The disadvantage is that the paging method is not good, and the specific page number cannot be displayed. but there is no better solution, so I have to do this first, if anyone has a paging method similar to this forum, I am very grateful to you! Visit my personal website: web.nyist.net ~ Wbgwrq. I will show you my practical results. The disadvantage is that the paging method is not good and the page number cannot be displayed, but there are no other better solutions, so we have to do so first. if anyone has a paging method similar to this forum, I am very grateful to you! Visit my personal small website: http://web.nyist.net /~ Wbgwrq, no nonsense. let's get started ......

// The table structure is as follows:
// Creat. SQL
// Simple description: the topic sequence number of the RootId; Layer: The Post level and indentation basis; Orders: The Post order
Create table over_post (
Id int (11) not null auto_increment,
Title varchar (80) not null default ',
Content text,
Postat datetime not null default '2017-00-00 00:00:00 ',
Readed int (11) not null default '0 ',
Size int (11) not null default '0 ',
Rootid int (11) not null default '0 ',
Orders int (4) not null default '0 ',
Layer int (4) not null default '0 ',
Primary key (id)
) TYPE = MyISAM;
// Creat. SQL End

// Post a root Post, that is, a post with a value of 0 for "RootId", "Layer", and "Orders"
// Said. php
// Begin

// Said. php End


// Post content and post it on this page
// Content. php
// Begin

$ Result = mysql_query ("select

Over_post.title, over_post.content, over_post.postat, over_post.readed, over_post.rootid, over_post.la

Yer, over_post.orders from over_post where over_post.id = $ id ");
$ Readed = mysql_result ($ result, 0, "readed ");
$ Title = mysql_result ($ result, 0, "title ");
$ Content = mysql_result ($ result, 0, "content ");
$ Date = mysql_result ($ result, 0, "postat ");
$ Rootid = mysql_result ($ result, 0, "rootid ");
$ Orders = mysql_result ($ result, 0, "orders ");
$ Layer = mysql_result ($ result, 0, "layer ");
?>












Publisher:
Subject: 《 "

Readed: ]
Internal capacity:




Forum posts

















Question:





Content:














// Content. php End

// Update the database
// Post. php
// Begin

$ Content = nl2br (htmlspecialchars ($ content ));
$ Title = htmlspecialchars ($ title); // you cannot use html on the title.
$ Date = date ("Y-m-d H: I: s ");
$ Length = strlen ($ content );

If (isset ($ said) // post a new post
{
$ Query = "insert into over_post

Values (null, '$ title',' $ content', $ user_id, '$ date', 0, $ length, $ img ,',',')";
$ Result = mysql_query ($ query) or die (mysql_error ());
$ R = mysql_query ("select max (id) from over_post ");
$ Rootid = mysql_result ($ r, 0) + 0;
Mysql_query ("update over_post set rootid = $ rootid where ID = $ rootid") or die (mysql_error ());
}

If (isset ($ reply): // post a post

Mysql_query ("update over_post set orders = orders + 1 where rootid = $ rootid and orders> $ orders") or

Die (mysql_error ());

$ Layer = $ layer + 1;
$ Orders = $ orders + 1;
$ Query = "insert into over_post

Values (null, '$ title',' $ content', $ user_id, '$ date', 0, $ length, $ img, $ rootid, $ orders, $ layer) ";

$ Result = mysql_query ($ query) or die (mysql_error ());

Endif;
If ($ result ){
Include "list. php ";
}
?>
// Post. php End

// Highlights all posts and displays them by page
// List. php
// Begin

// Find the latest topic's rootid
$ Query = "select max (rootid) as maxid1, min (rootid) as minid1 from over_post ";
$ Result = mysql_query ($ query );
$ Maxid1 = mysql_result ($ result, 0, "maxid1 ");
$ Startid1 = mysql_result ($ result, 0, "minid1 ");
If (! ($ Maxid1> 0) $ maxid1 = 0;
If (! ($ Startid1> 0) $ startid1 = 0;
$ Totalid1 = $ maxid1; // This is the largest value of the room. $ maxid1 must be changed according to $ nextmaxid1.
If ($ nextmaxid1> 0) $ maxid1 = $ nextmaxid1; // flip the page

// Calculate the minimum rootid. pay attention to the following desc, which is used with limit to ensure the range of selected records.
// If asc is used, retrieving 0th in mysql_result will be a big error!
$ Itemsperpage = 30;
$ Query = "select distinct rootid from over_post where rootid <= $ maxid1 order by rootid desc limit

$ Itemsperpage ";
$ R = mysql_query ($ query );
$ N = mysql_num_rows ($ r );
If ($ n> 0 ){
$ Minid1 = mysql_result ($ r, $ n-1 );
$ Query = "select * from over_post where rootid <= $ maxid1 and rootid> = $ minid1 order by rootid

Desc, orders ";
$ Result = mysql_query ($ query );
$ Num = mysql_num_rows ($ result );

}
Else {
$ Minid1 = 0;
$ Maxid1 = 0;
Echo"

No more content ";
}

$ Query = "select distinct rootid from over_post where rootid> $ maxid1 order by rootid limit

$ Itemsperpage ";
$ R = mysql_query ($ query );
$ N = mysql_num_rows ($ r );
If ($ n> 0) $ up = mysql_result ($ r, $ n-1 );
Else $ up = $ totalid1;

$ Query = "select distinct rootid from over_post where rootid <$ minid1 order by rootid desc limit

$ Itemsperpage ";
$ R = mysql_query ($ query );
$ N = mysql_num_rows ($ r );
If ($ n> 0) $ down = mysql_result ($ r, 0 );
Else $ down = $ maxid1;
?>















Href = "javascript: window. location. reload ()" class = a1> refresh
Homepage "class = a1>

Previous Page
"Class = a1> Next page
: $ Startid1-$ totalid1 ";?>

Echo"
    ";
    While ($ array = mysql_fetch_array ($ result )){
    $ Id = $ array ["id"];
    $ Title = $ array ["title"];
    $ Content = $ array ["content"];
    $ Postat = $ array ["postat"];
    $ Readed = $ array ["readed"];
    $ Size = $ array ["size"];
    If ($ size = 0) $ size = "no content ";
    Else $ size. = "Bytes ";
    $ Rootid = $ array ["rootid"];
    $ Orders = $ array ["orders"];
    $ Layer = $ array ["layer"];

    $ Ul = ""; // start the tree structure
    $ _ Ul = "";
    For ($ j = 0; $ j <$ layer; $ j ++ ){
    $ Ul = $ ul ."
      ";
      $ _ Ul = $ _ ul ."
    ";
    }
    Echo $ ul ."
  • "." $ Title ($ size )【

    ". Author."] $ postat <被读:$readed>
    ". $ _ Ul;
    Flush ();
    // Tree structure ends
    }
    ?>

Href = "javascript: window. location. reload ()" class = a1> refresh
Homepage "class = a1>

Previous Page
"Class = a1> Next page
: $ Startid1-$ totalid1 ";?>



// List. php End

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.