php - Undefined offset: 0 in yii2 -


i have code in model, , result of that, got undefined offset: 0 should solve that? i've tried declare new variable, still nothing change. thank

public function sendsms() {     $model2 = sibustudent::find()->innerjoin('sibu_payment', 'sibu_payment.virtual_id=sibu_student.virtual_id' )->where('sibu_student.phone1 != "null" '  ) ->all();     $model3 = sibustudent::find()->innerjoin('sibu_payment', 'sibu_payment.virtual_id=sibu_student.virtual_id' )->where('sibu_student.student_name != "null" '  ) ->all();     $model4 = sibupayment::find()->where('sibu_payment.total_payment != "null" '  )->all();     $model5 = sibupayment::find()->where('sibu_payment.sms_status != "null" ')->all();     $count = sizeof($model2);      for($a=0; $a<5; $a++){         if ($model5[$a]->sms_status == 0) {          $no = $model2[$a]->phone1;         $message = 'kepada bapak/ibu dari '.$model3[$a]["student_name"].',tagihan (spp,asrama,kantin,adm) rp.'.$model4[$a]["total_payment"].' dibayarkan sesuai tagihan. sms ini tidak untuk dibalas, jika ada yang kurang jelas diberitahukan kepada siswa dan menanyakan kepada kami. salam';          if (strlen($message) < 160)         {             $outbox = new outbox;             $outbox->creatorid = 'gammu';             $outbox->textdecoded = $message;             $outbox->destinationnumber = $no;             $outbox->save();         }     //batas     } } 

you have try way find data models not null clause. model checks not null condition. because model has no element key 0 in case why returns undefined offset 0

sibupayment::find()->where(['not', ['sibu_payment.total_payment' => null]])->all(); 

for example ['not', ['attribute' => null]] result in condition not (attribute null)

check more: http://www.yiiframework.com/doc-2.0/yii-db-query.html#where()-detail


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -