从codeigniter中的select语句中获取值?

时间:2014-03-02 15:15:53

标签: php codeigniter

   $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语句中获取last_sess_id值

请帮帮忙?

1 个答案:

答案 0 :(得分:2)

此处, $q->result() 会返回一组结果,而不是那样,您需要获取一行。因此,请使用 $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);
}      

希望这会有所帮助:)