magicmoose Posted July 16, 2007 Share Posted July 16, 2007 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 More sharing options...
sasa Posted July 16, 2007 Share Posted July 16, 2007 look mysql_num_rows() function Link to comment https://forums.phpfreaks.com/topic/60263-row-counting-trouble/#findComment-299747 Share on other sites More sharing options...
MrXander Posted July 16, 2007 Share Posted July 16, 2007 Instead, use: $rows = mysql_num_rows($count); Link to comment https://forums.phpfreaks.com/topic/60263-row-counting-trouble/#findComment-299749 Share on other sites More sharing options...
magicmoose Posted July 16, 2007 Author Share Posted July 16, 2007 It's returning 1 every time now ??? Link to comment https://forums.phpfreaks.com/topic/60263-row-counting-trouble/#findComment-299754 Share on other sites More sharing options...
JayBachatero Posted July 16, 2007 Share Posted July 16, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.