Jump to content

Recommended Posts

For a query such as:

 

SELECT count(*) FROM table LIMIT 5

 

What would be the best way to count the rows found?

 

I'm aware you can use: mysql_num_rows (though I don't think you can use count() with this), mysql_result, and mysql_fetch_row, depending on the circumstance.

 

I've heard mysql_result($rows, 0) is the most efficient, however, if there are no rows found, it will give an error.

 

So what do you recommend?

Link to comment
https://forums.phpfreaks.com/topic/165661-row-counting/
Share on other sites

LIMIT simply LIMITS the amount of rows returned by the query before telling mysql to stop searching.

 

COUNT() counts and returns the number of rows returned and can be accessed when fetching the data. Although I'm not sure how it's used when fetched unless used as-

 

"SELECT COUNT(*), fieldName As num FROM table"

//Then when its pulled into an associative array, for example you can access it using 

$count = $row['num'];

Link to comment
https://forums.phpfreaks.com/topic/165661-row-counting/#findComment-874386
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.