yii - Outputting values not equal to certain values in yii2 -


i output variables not equal values returns error of

failed prepare sql: select * `tblsuunit` `unitid` != :qp0 

there 2 models first model getting array of ids

public function actionsunits($id){     $unitslocation = new unitslocation();     $id2 = unitslocation::find()->where(['officelocationid'=>$id])->all();       foreach( $id2 $ids){       print_r($ids['unitid']."<br>");       }     } 

this outputs ids as

8 9 11 12 13 14 16 

i take id , compare model(units model) , id values not similar above , output

so have added

 $idall = units::find()->where(['!=', 'unitid', $ids])->all(); 

so whole controller action becomes

public function actionsunits($id){     $unitslocation = new unitslocation();     $id2 = unitslocation::find()->where(['officelocationid'=>$id])->all();       foreach( $id2 $ids){          $idall = units::find()->where(['!=', 'unitid', $ids])->all();       }      var_dump($idall);  } 

this units model table:

enter image description here

if working should return 7 , 10

what wrong..

you should fix code , use not in condition, e.g. :

// $uls array of unitslocation objects $uls = unitslocation::find()->where(['officelocationid'=>$id])->all();   // $uids contain unitids $uids = \yii\helpers\arrayhelper::getcolumn($uls, 'unitid');  // use not in condition $units = units::find()->where(['not in', 'unitid', $uids])->all();  $idall = \yii\helpers\arrayhelper::getcolumn($units, 'unitid'); 

read more activequery::where() , arrayhelper::getcolumn().


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -