[eluser]ibnclaudius[/eluser]
Quote:Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`this->users_table` . users.id AND sessions.token = $this->users_table . 8a4668b' at line 3
Code:
SELECT `users`.`id` AS id, `users`.`name` AS name, `users`.`email` AS email, `users`.`type` AS type
FROM (`users`)
INNER JOIN `sessions` ON `sessions`.`user_id` = $`this->users_table` . users.id
AND sessions.token = $this->users_table . 8a4668b91e275e020c54444ae9e5cbbc81fba13a
WHERE `sessions`.`token` = '8a4668b91e275e020c54444ae9e5cbbc81fba13a'
I can make it work, like this:
Code:
$query = $this->db->select($this->users_table . '.id AS id, ' . $this->users_table . '.name AS name, ' . $this->users_table . '.email AS email, ' . $this->users_table . '.type AS type')
->from($this->users_table)
->join($this->sessions_table, $this->sessions_table . '.user_id = ' . $this->users_table . '.id', 'INNER')
->where($this->sessions_table . '.token', $token)
->get();
But I want to put the where($this->sessions_table . '.token', $token) inside the join clause, because I have another $query like this and works.
Code:
$query = $this->db->select($this->schools_table . '.id AS id, ' . $this->schools_table . '.name AS name')
->from($this->schools_table)
->join($this->users_schools_table, $this->users_schools_table . '.school_id = ' . $this->schools_table . '.id AND ' . $this->users_schools_table . '.user_id = ' . $user_id, 'INNER')
->order_by($this->users_schools_table . '.created', 'DESC')
->limit(1)
->get();