Tree-Type Forum recursive acceleration
The General forum is recursive to the entire table
If only recursive result, then the speed will be much faster, moreover, access to result is to access the server memory.
We generally use the following statement to make the cursor move
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
But recursive result, we have only one result, when the cursor is uncertain, we do not know whether the current cursor records meet our requirements
PHP provides a function for the user to specify the cursor location
BOOL Mysql_data_seek (resource result_identifier, int row_number)
This is a function that everyone should be able to read.
Let me tell you about my ideas.
For the implementation of the Forum page, the table structure is designed as follows:
Table name: Newestbbs (latest post sorted by 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, or the last reply to submit the time
Table name: BBS
Structure:
ID of the post itself
Fathered Parent Posts ID
Rootid Root Posts ID
Time posted
.... other field.
Ideas:
Get the latest list of posts by Newestbbs (e.g. 20 posts per page list, select ID from Newestbbs order by time limit page -1,20)
Get result from the entire BBS table and show all the result of the root post
while (Bbs=mysql_fetch_array ($result))
{
SELECT * FROM BBS where rootid=bbs[' ID ' "ORDER by Time//(resulting in a second result, named Res)
$root =mysql_fetch_array (RES)
Show Root Posts
Dispreplybbs ($root [' id '], $res)//recursive display of all replies to this post
}
The recursive functions are as follows:
function Dispreplybbs ($id, $mysqlres)
{
for ($i =0; $i <>
{
Mysql_data_seek ($mysqlres, $i)//move the cursor to the specified position
http://www.bkjia.com/PHPjc/629388.html www.bkjia.com true http://www.bkjia.com/PHPjc/629388.html techarticle Tree Forum Recursive acceleration General Forums are recursive the entire table if only recursive result, then the speed will be much faster, moreover, access to result is to access the server memory. We generally pass the following language ...