从表格中获取行数时遇到问题。
这是我使用codeiginiter的mysql查询:
$this->db->where('rd', 1);
$this->db->where('id_user_first', $user_type);
$this->db->from("messaging");
$this->db->join('answers', "answers.id_message = messaging.id AND answers.id_user != '$user_type'");
$count_reponse = $this->db->count_all_results();
我收到此错误消息:
解析错误:语法错误,意外'''' (T_CONSTANT_ENCAPSED_STRING),期待','或';'在
答案 0 :(得分:0)
您可以针对您的问题尝试此解决方案:
请更改查询
$this->db->select('messaging.*, answers.*');
$this->db->from("messaging");
$this->db->join('answers', "answers.id_message = messaging.id");
$this->db->where('answers.id_user <>', $user_type);
$this->db->where('messaging.rd', 1);
$this->db->where('messaging.id_user_first', $user_type);
$count_reponse = $this->db->count_all_results();
答案 1 :(得分:0)
您需要转义引号或将内部双引号更改为单引号。
$this->db->join('answers', 'answers.id_message = messaging.id AND answers.id_user != '.$user_type.'','left');
尝试此查询:
$this->db->where('rd', 1);
$this->db->where('id_user_first', $user_type);
$this->db->from("messaging");
$this->db->join('answers', 'answers.id_message = messaging.id', 'left');
$this->db->where('answers.id_user !=', $user_type);
$count_reponse = $this->db->count_all_results();
我希望它会有所帮助。如果有任何错误,请发表评论。