How Do I Query A Table With Multiple Primary Key Values?


(huss@tahn.biz) #1

In the example below $subscribersResources returns all matched records for subscriber id 1, lets say 20 matches.

Now I want to use the id_resources field in $subscribersResources to query another table called resources.





$subscribersResources = SubscribersResources::model()->findAll("id_subscriber='1'");

$resources = Resources::model()->findAll(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?);




I’m a beginner in case it isn’t obvious.


(Alexander Makarov) #2

It can be:




$subscribersResources = SubscribersResources::model()->findAll("id_subscriber='1'");

$resources = Resources::model()->findAll('id=:id', array('id' => $subscribersResources->id_resources));



But I’d check http://www.yiiframework.com/doc/guide/1.1/en/database.arr


(huss@tahn.biz) #3

Thanks for the quick reply but yii logs and error: Trying to get property of non-object. If it helps this is the actual code.




  /**

     * @param string

     * @return string

     * @soap

  */  

  public function getResources($userInfo) {

  	    $response = array();

  		$userInfo = json_decode($userInfo, true);

  	     	     	   

  	    if(!$this->isValidAuthKey($userInfo['authKey'])){

			$response['error'] = 'Access denied';

			return json_encode($response);

  	    } else {

			$subscriber = Subscribers::model()->find("username='" . $this->getUserIdFromKey($userInfo['authKey']) . "'");

			$subscriberResources = SubscribersResources::model()->findAll("id_subscriber='" . $subscriber->id . "'");

			$resources = Resources::model()->findAll('id=:id', array('id' => $subscriberResources->id_resource));

			return json_encode($resources);

  	    }

  }