Note: It was working on single view page, but once I pass it to User Dashboard it will be showing error.
I was trying to pass user data from database to form table but it was showing error
Here’s my code:
public function questionList() {
$list = new QuestionsModel();
$data['questionList'] = $list->findAll();
return view('user/dashboard', $data);
}
Note that I had already have my QuestionsModel created
Here’s my dashboard.php section of the code
<table class="table">
<thead>
<tr>
<th>User ID</th>
<th>Lists</th>
<th>Answered</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php foreach($questionList as $list) { ?>
<tr>
<td><?= $list['user_id'] ?></td>
<td><?= $list['list'] ?></td>
<td><?= $list['answered'] ?></td>
<td><?= $list['status'] ?></td>
</tr>
<?php } ?>
</tbody>
</table>
How can I solve this please?
2
Answers
You don’t have a key in the foreach loop. By adding $data before accessing $questionList, you are explicitly telling the view to look for the $questionList variable in the $data array that you passed to the view.
I hope this will works for you :
still face issue add comment so i can help more.
My route :
My Controller :
My View File :
My Output :