MySQL-Look at PHP has an example, do not understand why she did not do so, would it be good to do so?

Source: Internet
Author: User

The example is this table, she takes two result sets here, one to get the total number of rows, generate the following Operation panel,
The other generates the above data.

I'm just wondering, just using a total result set is OK, the index array of the result set can also generate the above word,

Why not use two result sets?

Is this good for performance, or is it another reason?

Reply content:

The example is this table, she takes two result sets here, one to get the total number of rows, generate the following Operation panel,
The other generates the above data.

I'm just wondering, just using a total result set is OK, the index array of the result set can also generate the above word,

Why not use two result sets?

Is this good for performance, or is it another reason?

It is not very good to bring the question directly, for the following reasons:
Now that you have asked for doubt, the suspicion is that you have your own answer, but you are not sure that you are right.
In this case, I am very much looking forward to your question and also write your own solution in it, there are two advantages:
1-Your answer is not right, others can be pointed to point out the problem
2-Your answer is yes, we praise you, you gain confidence.

In fact, a lot of information contains a variety of errors, it is true that the second statement should be SELECT COUNT (*).

Now that you've tagged MySQL, the positive solution to this SQL should be

select SQL_CALC_FOUND_ROWS * from table limit x, y

Then by select found_rows() getting the total number of records that match the criteria.

When you have thousands of data, I think it's easy to understand the difference between the 10 rows and the total fetch performance.

Do not return the total number of records, how do you calculate the number of pages

Each page of data returns only n data via limit x, Y,

Paging is to avoid getting too much data at once.

  • 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.