因为我的codeigniter返回语法错误?
$handler_feedback = $this->CI->db
->select('
feedback.id as feedback_id,
feedback.titulo,
relacion_feedback_usuario_principal.valor
')
->from('feedback')
->join(
'relacion_feedback_usuario_principal',
'
relacion_feedback_usuario_principal.feedback_id = feedback.id AND
relacion_feedback_usuario_principal.usuario_principal_id = 20
',
'left'
)
->get();
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 '' at line 3
SELECT `feedback`.`id` as feedback_id, `feedback`.`titulo`, `relacion_feedback_usuario_principal`.`valor` FROM (`feedback`) LEFT JOIN `relacion_feedback_usuario_principal` ON `relacion_feedback_usuario_principal`.`feedback_id` = `feedback`.`id` AND
Filename: /dir/file.php
Line Number: 289
Mi原始查询:
SELECT
feedback.id as feedback_id,
feedback.titulo,
relacion_feedback_usuario_principal.valor
FROM feedback
LEFT JOIN relacion_feedback_usuario_principal ON (
relacion_feedback_usuario_principal.feedback_id = feedback.id AND
relacion_feedback_usuario_principal.usuario_principal_id = 20
)
答案 0 :(得分:1)
它应该按照您编写的方式工作 它很简单,
$this->db->join('B', 'aCol = bCol AND bOtherCol = 0');
$this->db->get('A');
无论如何,您可以尝试其他方式(join
带where
子句),
$this->db->select('t1.id as feedback_id, t1.titulo, t2.valor');
$this->db->from('feedback as t1');
$this->db->join('relacion_feedback_usuario_principal as t2', 't1.id = t2.feedback_id', 'left');
$this->db->where('t2.usuario_principal_id', 20);
$query = $this->db->get();
答案 1 :(得分:0)
relacion_feedback_usuario_principal.feedback_id = feedback.id AND
relacion_feedback_usuario_principal.usuario_principal_id = 20
AND
和relaction_feedback_ususario_principal.usuario_principal_id=20
之间是否有空格?
答案 2 :(得分:0)
我得出的结论是我的代码还不错,这是codeigniter中的一个错误。