error on passing from controller to views in codeigniter?
i want to passing data from model to controller then to view this code
explain it.
the model
public function get_all_college_name() {
$q = $this -> db -> query('select * from college');
if ($q -> num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
the controller code
public function index() {
$this -> load -> model('retriver_data');
$data['rows'] = $this -> retriver_data -> get_all_college_name();
$this -> load -> view('home', $data);
//$this -> view_something('home', $data);
}
the view code
<body>
<?php
foreach ($rows as $r) {
echo $r -> name;
}
?>
</body>
the error appears
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/home.php
Line Number: 8
No comments:
Post a Comment