I have the following simple code:
The model:
function get_last_ten_entries()
{
$this->db->get('property');
}
controller:
public function load_recent()
{
$data['info'] = $this->propertymodel->get_last_ten_entries();
$this->load->view('load_property', $data);
}
view:
<?
echo $data['id'];
?>
This is not working. Am sure i am doing something wrong because the error shown says
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: views/load_property.php
Line Number: 2
Property is a table in the database in which there is a field called id. what’s going wrong?
Thank you all
To fix the error, you’ll need to use
$infoin your view, rather than$dataas your array indexes in your controller correspond to variables in your view.$this->db->get('property')returns all rows in the tableproperty, but your function name suggests that you are trying to get the last 10 entries. I suggest you read CodeIgniter’s Active Record documentation for more information. You also need toreturnyour query.You need to generate results from you query. CodeIgniter’s Query Results documentation provides useful information on how to use the results of your query. What you’re trying to achieve is a bit vague but you code could look something like this:
Model
Controller
View
Or, if you rather use an object, instead of an array: