我在我的視圖文件中出現此錯誤。這裏是我的代碼,請幫助我,告訴做什麼?調用未定義的函數結果()
<?php
//foreach($records->result() as $row):
foreach(result() as $row):
echo $row->title;
endforeach;
?>
這裏是我的控制文件:
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Hello extends CI_Controller
{
public function index()
{
$this->load->model('hello_model');
$data['records']=$this->hello_model->getAll();
$this->load->view('you_view',$data);
//$this->load->view('you_view');
}
}
?>
我也張貼在這裏我的模型文件。 Ihv嘗試了一些我,但仍然getiing這個錯誤。 Dnt knw wt要做。
<?php
class Hello_model extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function getAll()
{
$q=$this->db->get('test'); // query where 'test' is table name.
if($q->num_rows()>0)
{
foreach ($q->result() as $row)
{
$data[]=$row;
}
return $data;
}
}
}
?>
在模型中,檢查'num_rows',回'$ Q-> result_array後() ;' –
如果你想返回結果作爲數組,你爲什麼要用'$ q-> result()'? :D很高興看到[說明](http://codeigniter.com/user_guide/database/results.html) –
thnx回答frnd ...但它的工作現在.....我用$記錄在結果的位置()在查看文件中:) –