I want to populate all the data from my database to a table using <?php foreach; ?> but I can’t get it to work. Please check my code:
controller
$data['query'] = $this->db->query('SELECT * FROM users');
$this->load->view('users_view',$data);
View
<?php foreach ($query->result_array() as $row)
{ ;?>
<tr>
<td><?php echo $row['usrID'];?></td>
<td><?php echo $row['usrName'];?></td>
<td><?php echo $row['usrPassword'];?></td>
</tr>
<?php } ?>
<?php endforeach; ?>
I would reccommend the alternative syntax for your foreach in the view…
It looks like you should be having some syntax errors the way you have it.
EDIT – to point out your syntax issues.
This first semicolon would be like writing a foreach like this…
Opinion aside from the point of the question
You should be processing your data in the controller and simply sending an array of data to be displayed in the view, not the whole query object.
so…
Controller