Jump to content

Row counting trouble


magicmoose

Recommended Posts

Hi, I'm using LIMIT in my SQL query to create a paging effect for a gallery.  I need to count the total number of rows in the table, but I'm having a problem.  Instead of giving the number of rows, it simply returns the word "Array".

Any nudges in the right direction would be appreciated.

Here's the relevant part of the code, thanks.

 

$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM $gallery ORDER BY id ASC LIMIT $offset, $rowsperpage";
    $count = mysql_query("SELECT FOUND_ROWS()");
   $rows = mysql_fetch_row($count);
echo $rows;

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

You need to perform the query w/o the limit first.

 

$request = mysq_query("SELECT COUNT(*) FROM $gallery");
list ($totalRows) = mysql_fetch_row($request);
mysql_free_result($request);

 

I would recommend saving the value in a session that way you wont have to query the database each time.

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