pouncer Posted April 17, 2007 Share Posted April 17, 2007 $result = mysql_query("select count(*) AS tot_people_per_rating,rating FROM item_rating WHERE item_id='$item_id' GROUP BY rating"); i don't understand it at all guys Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 17, 2007 Share Posted April 17, 2007 SELECT count(*) AS tot_people_per_rating, rating This part of the query tell it to return two values. The first value is the number of records that are grouped together - more on this later. The 2nd value is from the rating field FROM item_rating This tells it what table to grab the data from WHERE item_id='$item_id' This instructs the query to only grab values for results where the item_id is a specific value GROUP BY rating This instructs the query to group records together where they have the same rating. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 17, 2007 Share Posted April 17, 2007 ahh Beat me too it (but explaind better!) Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 17, 2007 Author Share Posted April 17, 2007 so the count(*) thing, what does this actually count? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 17, 2007 Share Posted April 17, 2007 the found set Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 18, 2007 Share Posted April 18, 2007 Well, in this case it is counting the records in each grouped result. So, if there are 5 records in the table with the rating of 'B' your result set will include 1 record that represents those five records because of the GROUP BY clause. And the COUNT function wil create a value of 5. And the same process will create similar results for all other ratings in the table. 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.