2014-01-31 21 views
3
class Mymodel extends CI_Model 
{ 

    public function getData($passwd,$email) 
    { 
    //$flag=0; 


     $u->where('username', $email); 
     $u->where('password', $passwd); 
    $total = $u->count(); 
    echo $total; 

} 
} 

我想顯示總數。通過$u->count()返回的行,但我得到以下錯誤如何得到no。在記錄集變量中返回的行?

一個PHP錯誤遇到

嚴重性:注意

消息:未定義的變量:U

文件名:型號/ mymodel.php

行號:10

+1

正如錯誤所述,沒有定義名爲'$ u'的變量。 – mcserep

+0

你在哪裏設置變量'$ u' –

+0

謝謝大家 – John

回答

0

這將返回計數

public function getData($passwd, $email) 
{ 
    //$flag=0; 
    $this->db->where('username', $email); 
    $this->db->where('password', $passwd); 
    $total = $this->db->count_all_results('table_name'); 
    return $total; 
} 

上述方法返回的計數,您可以從您的控制器調用它只是

echo $this->mymodel->getData($passwd, $email); 

0

由於在該類的範圍內沒有變量$u,您會收到錯誤消息。您需要將它傳遞給函數

public function getData($passwd, $email, $u)

有幾種方法可以做到這一點,但是這是最簡單的解決方案。

相關問題