--- In [email protected], James Keeline <[EMAIL PROTECTED]> wrote:
>
> --- whoisquilty <[EMAIL PROTECTED]> wrote:
>
> > --- In [email protected], James Keeline <keeline@> wrote:
> > >
> > > SELECT vidno, COUNT(*) AS popular FROM tablename GROUP BY vidno
ORDER BY
> > > popular DESC LIMIT 10;
> > >
> > > James
> >
> >
> > Wow, that worked. Thanks, James.
> >
> > If I wanted to implement a ratings system, would I use the same
> > technique just with AVG()?
> >
> > Jeremy
>
> Yes, if you have another field (rating) with integer values like 1
to 5 you
> could use AVG(rating).
>
> As you may have noticed, GROUP BY eliminates duplicates and sorts in
ascending
> order by the field named in GROUP BY. That is why I had to add the
ORDER BY
> ... DESC clause to control the output. The LIMIT should be self
explanatory.
>
> MIN(), MAX(), AVG(), COUNT(), SUM() are examples of aggregate
functions which
> can (and often must) be used with GROUP BY.
>
> James
>
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