Мне нужен запрос, который будет возвращать «адрес электронной почты» и «имя пользователя» из $accounts_table и * из $profiles_table. Однако я не могу разобраться в синтаксисе JOIN. Я понимаю, как работают соединения, но мои запросы выдают синтаксические ошибки.
Код: Выделить всё
function get_userdata($id)
{
$data = array();
$this->db->get_where($this->profiles_table, array('user_id' => $id));
$this->db->join($this->accounts_table.'.email', $this->accounts_table.'.id = '.$this->profiles_table.'.user_id');
$data = $this->db->get();
return $data;
}
Я, наконец, получил запрос, делающий то, что должен, но мне пришлось прибегнуть к прямому использованию MySQL:
Код: Выделить всё
function get($id)
{
$record = $this->db->query('
SELECT ' . $this->profiles_table . '.*, ' . $this->accounts_table . '.username, ' . $this->accounts_table . '.email
FROM ' . $this->profiles_table . '
LEFT JOIN ' . $this->accounts_table . '
ON ' . $this->profiles_table . '.user_id = ' . $this->accounts_table . '.id
WHERE ' . $this->profiles_table . '.user_id = ' . $id
);
return $record->row_array();
}
Подробнее здесь: https://stackoverflow.com/questions/893 ... -get-omits
Мобильная версия