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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The recursion depth of C++ functions is limited, and exceeding this limit will result in a stack overflow error. The limit value varies between systems and compilers, but is usually between 1,000 and 10,000. Solutions include: 1. Tail recursion optimization; 2. Tail call; 3. Iterative implementation.

Yes, C++ Lambda expressions can support recursion by using std::function: Use std::function to capture a reference to a Lambda expression. With a captured reference, a Lambda expression can call itself recursively.

The recursive algorithm solves structured problems through function self-calling. The advantage is that it is simple and easy to understand, but the disadvantage is that it is less efficient and may cause stack overflow. The non-recursive algorithm avoids recursion by explicitly managing the stack data structure. The advantage is that it is more efficient and avoids the stack. Overflow, the disadvantage is that the code may be more complex. The choice of recursive or non-recursive depends on the problem and the specific constraints of the implementation.

Discuz forum permission management: Read the permission setting guide In Discuz forum management, permission setting is a crucial part. Among them, the setting of reading permissions is particularly important, as it determines the scope of content that different users can see in the forum. This article will introduce in detail the reading permission settings of the Discuz forum and how to flexibly configure it for different needs. 1. Basic concepts of reading permissions In the Discuz forum, reading permissions mainly include the following concepts that need to be understood: Default reading permissions: Default after new user registration

Laravel is a popular PHP development framework, but it is sometimes criticized for being as slow as a snail. What exactly causes Laravel's unsatisfactory speed? This article will provide an in-depth explanation of the reasons why Laravel is as slow as a snail from multiple aspects, and combine it with specific code examples to help readers gain a deeper understanding of this problem. 1. ORM query performance issues In Laravel, ORM (Object Relational Mapping) is a very powerful feature that allows

Tail recursion optimization (TRO) improves the efficiency of certain recursive calls. It converts tail-recursive calls into jump instructions and saves the context state in registers instead of on the stack, thereby eliminating extra calls and return operations to the stack and improving algorithm efficiency. Using TRO, we can optimize tail recursive functions (such as factorial calculations). By replacing the tail recursive call with a goto statement, the compiler will convert the goto jump into TRO and optimize the execution of the recursive algorithm.

A recursive function is a technique that calls itself repeatedly to solve a problem in string processing. It requires a termination condition to prevent infinite recursion. Recursion is widely used in operations such as string reversal and palindrome checking.

Recursive definition and optimization: Recursive: A function calls itself internally to solve difficult problems that can be decomposed into smaller sub-problems. Tail recursion: The function performs all calculations before making a recursive call, which can be optimized into a loop. Tail recursion optimization condition: recursive call is the last operation. The recursive call parameters are the same as the original call parameters. Practical example: Calculate factorial: The auxiliary function factorial_helper implements tail recursion optimization, eliminates the call stack, and improves efficiency. Calculate Fibonacci numbers: The tail recursive function fibonacci_helper uses optimization to efficiently calculate Fibonacci numbers.
