2014-03-12 35 views
0

我想查看我查看的最後一個查詢結果,但我無法做到。請引導我。 我從數據庫中選擇記錄,並希望顯示它的視圖,但我的查詢結果是錯誤的,但我在mysql中測試這個查詢,它返回的記錄。我需要看到我的最後一個查詢結果我該怎麼做?顯示最後一個查詢結果在視圖中

模型:

function pub_article(){ 
    $where=array('public'=>'1'); 
    $query=$this->db->get_where('article',$where); 

    echo $this->db->last_query(); 
    exit; 

    if($query->num_rows() >0) 
     return $query->result(); 
    else 
     return false; 
} 

cotroller

$data['pub']=$this->mymodel->pub_article(); 
$this->load->view('first',$data); 

視圖

foreach($pub->result() as $row){ 
    echo $row->title; 
} 

我寫回波$這 - > DB-> last_query() ;出口;在get_where之後,它是否是正確的地方?我如何看待它?

回答

0

「exit」將您帶出pub_article()函數,因此沒有其他運行。

刪除該行

0

U的使用退出終止UR腳本...刪除行和更改代碼,這個..

型號:

function pub_article(){ 
    $where=array('public'=>'1'); 
    $query=$this->db->get_where('article',$where); 

    if($query->num_rows() >0) 
     return $query->result(); 
    else 
     return false; 
} 

現在看你最後查詢結果ü可以做到這一點..在你的控制器

function your_controller { 
    $data['pub'] = $this->my_model->pub_article(); 
    echo '<pre>';var_dump($data);exit; //use this line.. comment this line to run script again 
    echo '<pre>';print_r($data);exit; //or this line .. comment this line to run script again 

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