0
我設法獲取返回的數據行以進行特定搜索,但無法獲取已找到的行數。這裏是我的代碼如何獲取Codeigniter中的數據庫查詢後的行數?
我的控制器
function searchdata(){
$result = $this->posts->search($_POST['searchterm']);
$data['posts']= $result['rows'];
$data['num_results']= $result['num_rows']; // num_rows is the number of rows returned from a search
$this-> load-> view('results_index',$data);
}
我的模型
function get_search($keyword)
{
$q = $this-> db-> select('*')-> from ('blog');
$q= $this->db->like('title',$keyword);
$q= $this->db->or_like('description',$keyword);
$results['rows']= $q-> get()-> result();
//$results['num_rows']= $q-> num_rows(); <--- this doesn't work, invalid method, commented out
return $results;
}
如果有幫助,這http://ellislab.com/codeigniter/user-guide/database/results.html也許能幫助你。我以爲它會
謝謝你的傢伙。
完美的作品。當這個錯誤再次發生時,我會更關心這些事情。謝謝! – Matt