Jump to content

[SOLVED] Counting DIFFERENT values in a MySQL table


spiceydog

Recommended Posts

I have figured out how to get MySQL to count how many rows there are with the SAME name in a specific value but I need it to count the number of DIFFERENT values there are in a specific value. For instance my current code is:

$query = "SELECT user, count(albumname)

FROM albuminfo

GROUP BY user

ORDER BY albumname";

 

$result = mysql_query($query) or die("Couldn't execute query because: ".mysql_error());

while ($data = mysql_fetch_array($result)){

 

$posts = $data['COUNT(albumname)'];

}

{

echo "$user has $posts post(s)";

}

 

The problem is that I have 6 lines in the database that have the same value for "albumname" and of course they are counted seperately. What I want is for the script to recognize that all 6 lines are exactly the same and only read them as 1.

thank you!!!!

 

but what is the meaning of the "as albumcount"? i've never seen that before

 

also I am getting this error:

Couldn't execute query because: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause

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.