php - SQL Query logic with zend framework -


so, situation in logics kind'a bad, , math not good, need "building" query fetch information 3 different tables join query. structure this:

  • users table : primary key "id"
  • campaigns table : primary key "id"
  • user_campaign table : user_id, , campaign_id rows.

i want pull campaigns doesn't exist in user_campaign table user id x.

my query zend framework. appreciate kind of help, thanx, , evening israel!

my current query:

$q = $this->select()                 ->setintegritycheck(false)                 ->from(array('c' => 'campaigns'))                 ->join(array('uc'=> 'user_campaign'), 'uc.campaign_id != c.id , uc.user_id != 1', array('campaign_id', 'user_id')); 

try query out, using left join, , adding on joined table valid id being null, return results don't exist on right side of join

public function check_access($campaign_id, $user_id) {     $q = $this->select()         ->from(array('c' => 'campaigns'))         ->joinright(array('uc'=> 'user_campaign'), 'uc.campaign_id = c.id', array('campaign_id', 'user_id'));         ->where('uc.user_id != ?', $user_id)         ->where('campaign_id = ?', $campaign_id);      // user has entry, return false     if($this->fetchrow($select))         return false;      // user wasn't found, create entry, , return true     $this->insert('users_campaigns', array(         'user_id'       => $user_id,         'campaign_id'   => $campaign_id     ));      return true; } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -