Home >Backend Development >PHP Tutorial >Tree Forum Recursive Acceleration_PHP Tutorial
Tree forum recursion acceleration
General forums recurse the entire table
If only the result is recursed, the speed will be much faster, and accessing the result is accessing the server memory.
We usually move the cursor through the following statement
while($row=mysql_fetch_array($res))
The principle is that every time mysql_fetch_array($res) is executed, the cursor will automatically move down until the end
But when it comes to recursive result, we only have one result. , when the cursor is uncertain, we have no way of knowing whether the current cursor record meets our requirements
php provides a function that allows users to specify the cursor position
bool mysql_data_seek (resource result_identifier, int row_number)
Everyone should use this function Can you understand?
Let me talk about my ideas below.
In order to realize 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 there is no reply, it is the root post submission time, otherwise it is the last reply submission time
Table name: bbs
Structure:
id of the post itself id
fathered parent post id
rootid root post id
time posting time
………. Other field
ideas:
first get the latest post list from newestbbs (such as list on each page 20 root posts select id from newestbbs order by time limit Page number -1,20)
After getting the result, get and display all the root posts of the result from the entire bbs table
while(bbs=mysql_fetch_array($result) )
{
select * from bbs where rootid=bbs['id'] order by time //(The second result is obtained, named res)
$root=mysql_fetch_array(res)
use using using using using using out out out out out out out out Out out of ' mysqlres)
{
for($i=0;$i
mysql_data_seek($mysqlres,$i) //Move the cursor to the specified Location
http://www.bkjia.com/PHPjc/629388.html
www.bkjia.com