2014-03-02 109 views
0
$user_id = 1; 
    $sq = "SELECT last_sess_id from user_login WHERE user_id = ?"; 
    $q = $this->db->query($sq, array($user_id)); 
    if($q->num_rows() > 0) 
     { 
      foreach($q->result() as $result) 
       { 
       $result->last_sess_id;  
       } 
     }   

    $user_password_encrypt= sha1($last_sess_id."shelfbudencryption".$user_login_pass.$user_login_email); 

如何從select語句從codeigniter中的select語句獲取值?

請幫助得到last_sess_id價值?

+0

怎麼可能'$ user_id'定義? – SaidbakR

+0

@vini顯示'user_login'的表定義 –

回答

2

這裏,$q->result()將返回一組結果,intead那,你需要得到一個行。因此,使用$q->row()

$sq = "SELECT last_sess_id from user_login WHERE user_id = ?"; 
$q = $this->db->query($sq, array($user_id)); 
if($q->num_rows() > 0) 
{ 
    $result = $q->row(); 
    $user_password_encrypt=sha1($result['last_sess_id']."shelfbudencryption".$user_login_pass.$user_login_email); 
}  

希望這有助於:)