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