Recursive acceleration of tree Forum

Source: Internet
Author: User

Recursive acceleration of tree Forum
The entire table is recursive in common forums.
If only recursive results are returned, the speed will be much faster. Besides, the access result is used to access the server memory.
We usually move the cursor through the following statement.
While ($ row = mysql_fetch_array ($ res ))
The principle is that when mysql_fetch_array ($ res) is executed every time, the cursor is automatically moved down until the end of the operation.
However, when recursive results are returned, we only have one result. When the cursor is not scheduled, we cannot know whether the current cursor record meets our requirements.
Php provides a function for you to specify the cursor position.
Bool mysql_data_seek (resource result_identifier, int row_number)
You can understand this function.
Let me talk about my ideas.
To implement Forum paging, the table structure is designed as follows:
Table Name: newestbbs (the latest posts are sorted by the last reply time)
Structure:
Id only records the id of the root post
Time if no reply is received, it is the time when the root post is submitted; otherwise, it is the time when the last reply is submitted.
Table Name: bbs
Structure:
Id of the post itself
Fathered parent post id
Root post id
Time posting time
.......... Other fields
Ideas:
First, newestbbs obtains the list of the latest posts (for example, select id from newestbbs order by time limit pages-1, 20)
Obtain the result from the bbs table and display the root posts of all results.
While (bbs = mysql_fetch_array ($ result ))
{
Select * from bbs where rootid = bbs ['id'] order by time // (the second result is obtained and named res)
$ Root = mysql_fetch_array (res)
Show root posts
Dispreplybbs ($ root ['id'], $ res) // recursively display all replies to this post
}
Recursive functions are as follows:
Function dispreplybbs ($ id, $ mysqlres)
{
For ($ I = 0; $ I <mysql_num_rows ($ mysqlres); $ I ++)
{
Mysql_data_seek ($ mysqlres, $ I) // move the cursor to the specified position

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.