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; Quote 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 Quote 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); Quote 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 ??? Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/60263-row-counting-trouble/#findComment-299760 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.