Monday, April 15, 2013

find all users from another table

hi guys,... can anyone help please,... 

I have a PhotoLike table where I have user_id field . I'll like to find all users from User table in PhotoLike (list) 

I got 2 users like photo,... I got a list array from PhotoLike which is fine: 

Array
(
    [59] => 59
    [48] => 48
)

next I want to find ALL users in User.id from PhotoLike.user_id 
I'm getting this error finding users: 
Undefined index:  PhotoLike [APP/controllers/photos_controller.php, line 1161] 

this is my photos_controller.php 

  function likes($id = null)
  {
      if(!($photo = $this->Photo->findById($id)))
      {
        $this->flash('error', ucfirst(i18n::translate('photo not found')));
        $this->redirect('/not_found');
      }

      $this->set('photo_likes', $photo_likes = $this->PhotoLike->find('list', array('conditions' => array('PhotoLike.photo_id' => $photo['Photo']['id']), 'order' => array('PhotoLike.created' => 'DESC'))));
      debug($photo_likes);

      $this->set('photo_like_users', $photo_like_users = $this->User->find('all', array('conditions' => array('User.id' => $photo_likes['PhotoLike']['user_id']) )));
      debug($photo_like_users);
  }

thanks in advance 
chris 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: