i got this fatal error when i run this on browser please solve my problem...i don't get whats wrong with this code.........Fatal error: Call to a member function where() on a non-object
Fatal error: Call to a member function where() on a non-object
model
<?php
class News extends CI_Model
{
function Users(){
//call model constructor
parent::Model();
//load database
$this->load->database();
}
public function get_all_news(){
$this->db->get('news');
if($query->num_rows()>0){
//return result set as associate array
return $query->result_array();
}
}
public function getnews($field,$param){
$this->db->where($field,$param);
$query=$this->db->get('news');
// return result set as accosiate array
return $query->result_array();
}
public function getnumnews(){
return $this->db->count_all('news');
}
}
?>
controller
<?php
class News_data extends CI_Controller{
public function Users(){
// load controller parent
parent::Controller();
// load ‘Users’ model
}
public function index(){
$this->load->model('News');
$data['users']=$this->News->getnews('id <',5);
$data['numusers']=$this->News->getnumnews();
$data['title']='Displaying user data';
$data['header']='User List';
// load ‘Show_data’ view
$data['title']='Display data';
$this->load->view('Show_data',$data);
}
}
?>
view
</head>
<body>
<h1><?php echo $header;?></h1>
<ul>
<?php foreach($users as $user):?>
<li>
<p><?php echo $user['id'].' '.$user['title'].' '.$user['tetxt'];?></p>
</li>
<?php endforeach;?>
</ul>
<p><?php echo 'Total number of users :'.$numusers;?></p>
</body>
</html>
?>