Jason Bassett Jason Bassett - 2 years ago 81
PHP Question

Codeigniter query - selecting a user by session ID and Logkey

Complete noob to Codeigniter (although I've been a developer for years), perhaps there's something I'm missing. I simply am unable to get this query working. No errors, no warnings/notices etc...

Why does this function not work? From what I'm reading in the CI manual for queries, this seems to be correct.

Any insight on this friends?

public function __construct(){
$this->CI =& get_instance();
$this->CI->db->select('id, first_name, last_name, email, password, logkey');
$this->CI->db->where('id', $this->CI->session->id);
$this->CI->db->where('logkey', $this->CI->session->logkey);
$result = $this->CI->db->get();
if($result->num_rows() == 1){
$this->id = $id;
$this->first_name = $first_name;
$this->last_name = $last_name;
$this->email = $email;
$this->password = $password;
$this->logkey = $logkey;


Answer Source

You try to set variables which you did not define

$this->id = $id;

$id is not defined anywhere in your constructor

You can do something like this:

$row = $result->row();
$this->id = $row->id;

You may look into the documentation

As found out inside the comments, $result->num_rows also needs parentheses.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download