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.

Link to comment
Share on other sites

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

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.