conan318 Posted November 9, 2011 Share Posted November 9, 2011 i have 12 distinct albums displaying 8 per page $number rows echo's out to be 1 so to me says my query is wrong how to count only distinct albums $sql = "SELECT COUNT(DISTINCT album) FROM belsgallery GROUP BY album"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r['0']; echo $numrows; // RETURNS 1 $rowsperpage = 8; $totalpages = ceil($numrows / $rowsperpage); Quote Link to comment https://forums.phpfreaks.com/topic/250752-pagination-count-distinct/ Share on other sites More sharing options...
conan318 Posted November 9, 2011 Author Share Posted November 9, 2011 the answer remove the grouping $sql = "SELECT COUNT(DISTINCT album) FROM belsgallery "; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r['0']; echo $numrows; // RETURNS 1 $rowsperpage = 8; $totalpages = ceil($numrows / $rowsperpage); Quote Link to comment https://forums.phpfreaks.com/topic/250752-pagination-count-distinct/#findComment-1286490 Share on other sites More sharing options...
xyph Posted November 9, 2011 Share Posted November 9, 2011 Do you want the number of distinct albums in the database? Or do you want to return how many duplicates of each album there are? You're kind of trying to do both there. You either want to COUNT(DISTINCT column) or GROUP BY column. Not both. Quote Link to comment https://forums.phpfreaks.com/topic/250752-pagination-count-distinct/#findComment-1286491 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.