thanks for your help, but this gives me a Mysql error.

my avgRatings function looks like this:

    function getRating($id=null) {

    if ($id)      {
            $avg_rating = $this->query("select avg(rating) from
ratings where picture_id = '".$id."'");
            $avg_rating1 = $avg_rating[0][0]['avg(rating)'];
            return $avg_rating1;
        }
    }

it works when i call this function from the pictures view action,
because there i have an picture id, but in the index i need to have
the rating for every picture in the database!

On 18 Okt., 01:34, hydra12 <[EMAIL PROTECTED]> wrote:
> If you have the relationship setup correctly, you don't have to use
> the ratings model.  You can do this in your controller:
>
> $this->set('ratings', $this->Picture->Rating->avgRating($id));
>
> That's all off the top of my head, but it should work.
>
> HTH,
> hydra12
>
> On Oct 17, 4:22 pm, nomex <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hey,
>
> > I have 2 Tables:
>
> > pictures
> > ratings
>
> > every rating belongs to a picture and every picture has many ratings.
> > (just a normal rating DB)
>
> > i want to make a list of every picture with it's average rating in the
> > picture view. Therefor i had made a avgRating function (gets the id of
> > the picture and returns the avg. Rating)  in the model of the rating
> > and used "uses (picture, rating)" in the picture controller. But i'm
> > not able get the data into the controller and the view.
>
> > can anyone pls help me?
>
> > thank you very much!- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to