[eluser]Yorick Peterse[/eluser]
Add the following code (don't forget to change it):
Controller
Code:
<?php
class some_class extends Controller {
//Constructor function
function __construct() {
parent::Controller();
}
//Index function
function index() {
//Load the comments model
$this->load->model('comments_model');
//Get the comments
$data = array (
'result' => $this->comments_model->get_comments()
);
//Load the view
$this->load->view('some_view',$data);
}
}
?>
The model
Code:
<?php
class Some_model extends Model {
//Function for the comments
function get_comments() {
//Create the query
$query = $this->db->get('comments');
//Check to see if there are any comments at all
if($query->num_rows() > 0) {
//Return the results
return $query->result();
}
//No comments
else {
show_error('No comments have been added yet');
}
}
?>
The view
Use a foreach loop as shown in the snippet, then use $row->database_column (e.g. $row->id) to output the result.
Code:
<?php foreach($result as $row): ?>
<h3><?php echo $row->name; ?></h3>
<?php endforeach; ?>