[eluser]LifeSteala[/eluser]
Hi,
Welcome to Code Igniter!
Firstly, you should look up Models in the user guide. Models is the layer in which your application communicates with the database. By not utilizing Models, you are moving away from the Model-View-Controller (MVC) approach.
So let me try to help you.
Model
Code:
class Messages extends Model
{
function Messages()
{
parent::Model();
}
function getMessages()
{
$this->db->select('*');
$this->db->from('msgboard');
$result = $this->db->get();
if (!$result) {
return false;
} else {
return $result;
}
}
}
Controller
Code:
class Thiscontroller extends Controller
{
function Thiscontroller()
{
parent::Controller();
$this->load->database(); // This should be autoloaded
$this->load->model('messages');
}
function index()
{
$myData['query'] = $this->messages->getMessages();
$this->load->view('feedback', $myData);
}
}
$myData is an array of key / value pairs. In CI, when passing an array to a view, the key becomes it's own variable which can be directly used as shown below in the foreach statement.
View
Code:
<ul>
<?php foreach ($query->result() as $row) { ?>
<li><?php echo $row->id; ?></li>
<li><?php echo $row->name; ?></li>
<li><?php echo $row->email; ?></li>
<li><?php echo $row->time; ?></li>
<li><?php echo $row->message; ?></li>
<? } ?>
</ul>
I'm processing query results in the view as in this case, you are only wanting to view the data/results. If there were to be data manipulation, generally you would do that in the controller then pass whatever you need to display through.
I hope all that makes sense.
Note: This code is untested. Errors may arise.