The very basic idea is like this:
You have a database with whatever name you've given to it (Code08, mydatabase etc.) as long as you set up the database connection correctly in application/config/database.php. Inside the database, you have a table with news items, e.g. news08.
You have a model that collects records from the news08 table, like this:
PHP Code:
public function get_all_news()
{
$query = $this->db->get('news08');
if ($query->num_rows() == 0) {
return FALSE;
}
else {
return $query->result();
}
}
In your controller, you call the model function get_all_news to get the news items:
PHP Code:
$data['records'] = $this->news_model->get_all_news();
Now, the $data['records'] variable holds the result of the model function, i.e. all records from the news08 table (if there are any).
Next, your controller outputs the $data to a view:
PHP Code:
$this->load->view('news/show_all_news_items',$data);
Important: the view file "show_all_news_items.php" is in the folder application/views/news
Finally, your view displays the result:
PHP Code:
<table>
<tr><th>Date</th><th>Title</th></tr>
<?php foreach($records as $record) : ?>
<tr>
<td><?= $record->date;?></td>
<td><?= $record->title;?></td>
</tr>
<?php endforeach; ?>
</table>
<?= is short for <?php echo