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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.