spiceydog Posted July 6, 2008 Share Posted July 6, 2008 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. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 7, 2008 Share Posted July 7, 2008 try SELECT user, COUNT(DISTINCT(albumname)) as albumcount from `albuminfo` ORDER BY albumname check my spelling (The group by is unneeded) Quote Link to comment Share on other sites More sharing options...
spiceydog Posted July 8, 2008 Author Share Posted July 8, 2008 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 Quote Link to comment Share on other sites More sharing options...
spiceydog Posted July 10, 2008 Author Share Posted July 10, 2008 SOLVED!! Quote Link to comment 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.