Re: Foreach loop with data from other model

2008-10-17 Thread nomex
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]

Re: Foreach loop with data from other model

2008-10-17 Thread hydra12
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 PROTE

Foreach loop with data from other model

2008-10-17 Thread nomex
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 r