2014-03-04 60 views
0

我該如何解決這個問題?查詢結果然後除,codeigniter和postgresql

從型號頁面

$query = $this->db->query("SELECT masters from table2 where table_id='table2-G' AND psced_id='58'");  
    //masters in an Integer type 

if ($query !=0){ 
    //code for dividing 

,但我得到一個錯誤

Message: Object of class CI_DB_postgre_result could not be converted to int 

我想在這裏的是,如果$查詢的值等於0,我會分裂。

+2

$查詢 - > NUM_ROWS () – fxfilmxf

+0

像@fxfilmxf所說的,使用'if($ query-> num_rows()> 0)' – ranisalt

+0

@fxfilmxf如果只有你把你的評論置於回答中。我可以檢查它。但tnx無論如何它的工作 – Kino

回答

1

我添加到原來的問題進行評論,而是使之官:

您可以檢查由像這樣的查詢返回的行數...

if ($query->num_rows() > 0) { 
    // your code 
} 
0

$ query是一個數組,可能是一個數組數組,所以你需要先檢查它的計數,然後獲取元素。一旦你有了單一的元素,你可以檢查它爲0,並做你的鴻溝。