Jump to content

Row Counting


Cless

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

Archived

This topic is now archived and is closed to further replies.

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