Undefined Variable and Invalid argument supplied for foreach(Code igniter) [duplicate]

Multi tool use
Multi tool use


Undefined Variable and Invalid argument supplied for foreach(Code igniter) [duplicate]



This question already has an answer here:



I have some problem with these codes. I already declared notification but the error keeps showing.



Here's my code


public function view_notification($id,$token= ''){
$this->isLoggedIn();


$data_applicant = array(
// get data using email
'token' => $token,
'applicant_info' => $this->model->getApplicantInfo($this->session->userdata('email'))->row(),
'notifications' => $this->model->notification($this->session->userdata('email'))->result_array(),
'notification' => $this->model->all_notification($this->session->userdata('email'))->result_array(),

);



if ($this->session->userdata('position_id') == '3') { // Applicant
$this->load->view('includes/applicant_header', $data_applicant);
$this->load->view('applicant/notification/notifation', $data_applicant);
}

}

}



Under view:


<div class="modal-body">
<?php foreach($notification as $noti): ?>


<h3>From: Administrator</h3><h5><?=$noti['notif_content']?></h5><p><?=$noti['date']?></p>
<hr>


<?php endforeach; ?>
</div>



Need help thanks!



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





make sure $data_applicant['notification'] is not empty . check for empty in your view
– pradeep
Jul 2 at 4:56



$data_applicant['notification']




1 Answer
1



In your code PHP is not able to find any array named as $notification is is inside an array called $data_applicant


$notification


$data_applicant



so please rewrite your for each as as


<?php foreach($data_applicant['notification'] as $noti): ?>



This will work please try.





Thanks! Sorry, I'm just new in codeigniter.
– Tristan
Jul 2 at 3:29





Please try . Is it working ???
– Pranav MS
Jul 2 at 3:30

IKf,5SiCWO,awkamZ2vEDa3m,f6hW6RIN5jdwbOcNqVL1F 53ojCsEU2PX0,RAgC,pP,RQQW4Qb qMByeOh400M iMNTPLIy
zhe8LAVMoeykrwFusonVJMfkQ39maExTg4Gp

Popular posts from this blog

Rothschild family

Boo (programming language)