--- In [email protected], James Keeline <[EMAIL PROTECTED]> wrote: > > --- whoisquilty <[EMAIL PROTECTED]> wrote: > > > I tried creating a query to output a rating and I'm not sure I've got > > it right: > > > > > > $ratingquery = "SELECT *, AVG(rating) as avgrating > > FROM rate > > WHERE videono = $vidvar > > GROUP BY rating"; > > $ratingresult = mysql_query($ratingquery) or die(mysql_error()); > > > > while ($rating = mysql_fetch_array($ratingresult)) > > { > > print $rating["avgrating"]; > > } > > > > > > The ratings belong in the ratings column. Each rating goes with its > > corresponding videono. There is a rateid that assigns an id for really > > no reason. > > > > I've added a WHERE statement because there will be multiple ratings > > for multiple videono. > > > > There are two rows that have ratings. They are both for the same > > videono. One is 1 and the other is 4. > > > > This query outputs this "1.00004.0000". > > > > What have I done wrong? > > > > Jeremy > > $ratingquery = "SELECT *, AVG(rating) as avgrating > FROM rate > WHERE videono = $vidvar > GROUP BY videono"; > > You only want one aggregate rating for each video, right? That is the column > to GROUP BY. > > James >
Thank you, James. Group by is still a little mystical to me. Jeremy
