Tree-Type Forum recursive acceleration

Source: Internet
Author: User
Tags table name time limit server memory
Recursive tree-Type Forum recursive acceleration
General forums are recursively whole tables
If only recursive result, the speed will be much faster, and access to the server memory.
We generally move the cursor through the following statement
while ($row =mysql_fetch_array ($res))
The principle is that when mysql_fetch_array ($res) Each time the cursor is automatically moved down until the end
But recursive result, we have only one result, when the cursor is uncertain, we cannot know whether the current cursor record meets our requirements
PHP provides a function for the user to specify the cursor position
BOOL Mysql_data_seek (resource result_identifier, int row_number)
We should be able to read this function.
Let me talk about my ideas.
For the implementation of the Forum pagination, table structure design is as follows:
Table name: Newestbbs (latest post with last reply time sorted)
Structure:
ID only records the ID of the root post
Time if there is no reply, then the root posting time, or the Last Post submission
Table name: BBS
Structure:
ID of ID post itself
Fathered parent Post ID
Rootid Root Post ID
Time to post
... the other field.
Ideas:
Newestbbs Gets the latest posts list (for example, each page listing 20 root posts Select ID from Newestbbs order by time limit pages -1,20)
Get result from the entire BBS and show all the root posts
while (Bbs=mysql_fetch_array ($result))
{
SELECT * FROM BBS where rootid=bbs[' ID ' is Order by Time//(this gives the second result, named Res)
$root =mysql_fetch_array (RES)
Show Root Posts
Dispreplybbs ($root [' id '], $res)//recursively show this post all replies
}
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 location
Bbsreply=mysql_fetch_array ($mysqlres)//Get the content of this cursor position post
if (bbsreply[' Fatherid ']== $id)
{
Determine if the parent of this post is given an ID
If yes, retract the display.
Dispreplybbs ($bbsreply [' id '], $mysqlres)//and recursively search for any child posts
If not, judge the next one.
}
}//Loop all result
}


If you have any objections, please post or mailto:chensiping@163.net. This article is not copyright protection, welcome to modify reproduced



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.