Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8661233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:26:57+00:00 2026-06-12T16:26:57+00:00

I have a large table (60+) millions of records. I’m using PHP script to

  • 0

I have a large table (60+) millions of records.

I’m using PHP script to navigate through this table.

PHP script (with pagination) loads very fast because:

The table engine is InnoDB thus SELECT COUNT() is very slow and mysql_num_rows() is not an option, so i keep the total row count (the number that i use to generate pagination) in a separate table (i update this record total_rows=total_rows-1 and total_rows=total_rows1+1 during DELETE and INSERT).

But the question is what to do with the pagination for search results?

Right now I’m doing this with 2 steps:

1.

$condition = " fname='rinchik' ";
$result = "SELECT * FROM my_large_table WHERE" . $condition;

Here i got all search results from DataBase.

2.
Now i need to count these results to create pagination.
I’m doing this:

$condition; <- we already have this from the step 1
$result_count = "SELECT COUNT(id) FROM my_large_table WHERE" . $condition;

And it’s kinda slow.

Would it be better if i will do it this way (with just one step)?:

$condition = " fname='rinchik' ";
$result = "SELECT * FROM my_large_table WHERE" . $condition;
$result_count = mysql_num_rows($result);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:26:58+00:00Added an answer on June 12, 2026 at 4:26 pm

    Use COUNT, internally the server will process the request differently.

    When doing COUNT, the server will only allocate memory to store the result of the count.

    When using mysql_num_rows, the server will process the entire result set, allocate memory for all those results, and put the server in fetching mode, which involves a lot of different details, such as locking.

    Think of it like the following pseudo scenarios:

    SELECT COUNT(*)

    Hey Bob, how many people are in the class room?

    mysql_num_rows

    Hey Bob, send all the people from the classroom over to me, … I’ll count them to get the number of people myself

    In summary, when using mysql_num_rows you are transferring all records to the client, and the client will have to calculate the count itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large table (more than 10 millions records). this table is heavily
I have a very large table (millions of records) containing approximately 8 fields as
I have a large table consisting of over 60 millions records and I would
I have a large table with millions of records. Table `price` ------------ id product
I have a very large table (few million records). The columns in the table
I have a relatively large table (a couple millions of records), multiple websites are
I have a very large dataset - millions of records - that I want
I have a very large table (15 million rows, this is an audit table).
I have a large table in mysql, about 1 million records. I'm using a
I have a large table with 10+ millions records in a SQL Server database.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.