I want to pass row fetched from database to view from controller.
foreach ($usertable->result() as $note) {
$note['title'];
$this->load->view('note',$note);
}
but it didn't work.
Strictly, not the right way to send data to view (not inside for loop). This will load the view the numbers of time the loop runs.
Enclosed all the notes data into a variable say via an array data['notes'] and the now in view you can use notes variable for fetching data.
Read docs for more info.
In controller:
$data['notes'] = $usertable->result();
$this->load->view('note', $data);
In view:
<table>
<tr>
<td>Note id</td>
<td>title</td>
</tr>
<?php foreach($notes as $n) { ?>
<tr>
<td><?php echo $n->id; ?></td>
<td><?php echo $n->title; ?></td>
</tr>
<?php } ?>
</table>
you can use following.
foreach ($usertable->result() as $note) {
$note[]=$note;
}
$note['title'];
$this->load->view('note',$note);
view(not insidefor loop). This will load theviewthe numbers of time the loop runs. Put on more code. What you really want to do here ??