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

  • Home
  • SEARCH
  • 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 152657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:39:46+00:00 2026-05-11T09:39:46+00:00

How can I count the number of rows that a MySQL query returned?

  • 0

How can I count the number of rows that a MySQL query returned?

  • 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. 2026-05-11T09:39:47+00:00Added an answer on May 11, 2026 at 9:39 am

    Getting total rows in a query result…

    You could just iterate the result and count them. You don’t say what language or client library you are using, but the API does provide a mysql_num_rows function which can tell you the number of rows in a result.

    This is exposed in PHP, for example, as the mysqli_num_rows function. As you’ve edited the question to mention you’re using PHP, here’s a simple example using mysqli functions:

    $link = mysqli_connect("localhost", "user", "password", "database");  $result = mysqli_query($link, "SELECT * FROM table1"); $num_rows = mysqli_num_rows($result);  echo "$num_rows Rows\n"; 

    Getting a count of rows matching some criteria…

    Just use COUNT(*) – see Counting Rows in the MySQL manual. For example:

    SELECT COUNT(*) FROM foo WHERE bar= 'value'; 

    Get total rows when LIMIT is used…

    If you’d used a LIMIT clause but want to know how many rows you’d get without it, use SQL_CALC_FOUND_ROWS in your query, followed by SELECT FOUND_ROWS();

    SELECT SQL_CALC_FOUND_ROWS * FROM foo    WHERE bar="value"     LIMIT 10;  SELECT FOUND_ROWS(); 

    For very large tables, this isn’t going to be particularly efficient, and you’re better off running a simpler query to obtain a count and caching it before running your queries to get pages of data.

    DEPRECATED as of 8.0.17 – as Etienne Bruines notes in the comments, using SQL_CALC_FOUND_ROWS is deprecated in 8.0.17 and will be removed in later versions. The recommendation is to issue a second query to calculate a count.

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

Sidebar

Ask A Question

Stats

  • Questions 64k
  • Answers 64k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer ControlCollection only implements IEnumerable, not IEnumerable<T>. That's easy to fix… May 11, 2026 at 10:55 am
  • added an answer We developed exactly what you are looking for on an… May 11, 2026 at 10:55 am
  • added an answer Most if not all GUI toolkits have a resize event… May 11, 2026 at 10:55 am

Related Questions

How can I count the number of elements in an array, because contrary to
How can i count the number of stored procedures in my database and is
In ANSI C++, how can I assign the cout stream to a variable name?
How can I count operations in C++? I'd like to analyze code in a
How can I count how many previous FootNoteReference nodes there are in an xml
How can I get programmatic access to the call stack?
How can I request a random row (or as close to truly random as
How can I set up my crontab to execute X script at 11:59PM every
How can I calculate the value of PI using C#? I was thinking it
How can I create this file in a directory in windows 2003 SP2: .hgignore

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.