0

I want to display the total number of rows in a table. When I do this following message is displaying in the view, I can't find the mistake in my code. Where is the mistake in the code?

The error that is displayed

A PHP Error was encountered Severity: Notice Message: Undefined variable: data Filename: views/admin_index_view.php Line Number: 15

Model Function

public function count_registerd_customers() {   
  $query = $this->db->query('SELECT * FROM tbl_customers');
  return $query->num_rows();
} 

Controller function

public function index() {
  $data['registered_customers'] = $this->admin_index_model->count_registerd_customers();

  $this->load->view('admin_index_view',$data);
}

On My View

<?php echo $data['registered_customers']; ?>
Ram
  • 3,092
  • 10
  • 40
  • 56
HPM
  • 11
  • 1
  • 2
  • Try `` on your view instead of `` –  Jun 25 '15 at 03:30
  • For your model another simple way to count result with codeigniter is `return $this->db->count_all_results('tbl_customers');` –  Jun 25 '15 at 03:39
  • hello wolfgang thanks for the response! i have tried your solution but it did not make any difference in the out put.do you see any other faults in my code above? – HPM Jun 25 '15 at 05:49
  • Did you load your model on to controller? $this->load->model('admin_index_model'); I cannot see it any where make sure when you have controller that class and file name like Admin_index_model and Admin_index_model.php –  Jun 25 '15 at 06:18
  • yes,model is there,i think the problem is not in the above code,i will look again,thanks for the help :) – HPM Jun 25 '15 at 06:58

0 Answers0