Jump to content

Count number of rows


The Little Guy

Recommended Posts

Is there a faster way to count the number of rows in a database other than mysql_num_rows? If there are over 10,000 reccords, wont mysql_num_rows be slower since you had to query all those rows first? I want to show how may records there are total in two different tables, one for number of users, and one for number of files(1 file = 1 row). So basically this will be on the home page, and will be ran many times, that seems like there will be too many connections to the database, if there are many page loads of the home page, then there are also many loads in the users section as well. Any other way to do this?

$sql = mysql_query("SELECT * FROM `files`");
$sql2 = mysql_query("SELECT * FROM `users`");
$rows_return = mysql_num_rows($sql);
$rows_return2 = mysql_num_rows($sql2);
echo $rows_return;
echo $rows_return2;
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.