[eluser]WanWizard[/eluser]
Controller:
Code:
class Test Extends Controller
{
function Test()
{
parent::Controller();
}
function index()
{
// data array for the view
$data = array();
// load the model
$this->load->model('my_model');
// fetch the rows
$data['rows'] = $this->my_model->get_rows();
//show the view
$this->load->view('my_view', $data);
}
}
Model:
Code:
class My_model Extends Model
{
function My_model()
{
parent::Model();
}
function get_rows()
{
// fetch the rows
$query = $this->db->get('table');
// return the result
if ( $query )
{
return $query->result();
}
else
{
return FALSE;
}
}
}
View:
Code:
<?php if ( $rows ) { ?>
<table>
<?php foreach ($rows as $row) { ?>
<tr>
<td><?=$row->field ?></td>
</tr>
<?php } ?>
</table>
<?php } ?>