Jump to content

Pagination count DISTINCT


conan318

Recommended Posts

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);

Link to comment
https://forums.phpfreaks.com/topic/250752-pagination-count-distinct/
Share on other sites

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);

 

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.

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.