【问题标题】:SQL + Ion Auth + CodeIgniter?SQL + Ion Auth + CodeIgniter?
【发布时间】:2012-04-19 02:48:02
【问题描述】:

我有以下 SQL:

SELECT (
(SELECT SUM(vote_score)
FROM question_votes 
JOIN questions
ON vote_question = q_id
JOIN users
ON q_author = users.id
WHERE q_author` = users.id) 
+ 
(SELECT SUM(vote_score)
FROM answer_votes 
JOIN answers 
ON vote_answer = a_id
JOIN users
ON a_author = users.id
WHERE a_author = users.id)) AS rep

我希望将其添加到此处(Ion Auth 的方法):

    $this->db->select(
            array(
                $this->tables['users'].'.*',
                $this->tables['groups'].'.name AS '. $this->db->protect_identifiers('group'),
                $this->tables['groups'].'.description AS '. $this->db->protect_identifiers('group_description'),
                "(SELECT COUNT(`a_author`) FROM `answers` WHERE a_author = users.id) + (SELECT COUNT(`q_author`) FROM `questions` WHERE q_author = users.id )  AS total_posts",
                "SELECT 
((SELECT SUM(vote_score)
FROM question_votes 
JOIN questions
ON vote_question = q_id
JOIN users
ON q_author = users.id
WHERE q_author` = users.id) 
+ 
(SELECT SUM(vote_score)
FROM answer_votes 
JOIN answers 
ON vote_answer = a_id
JOIN users
ON a_author = users.id
WHERE a_author = users.id)) AS rep"
            )
        );

但我收到以下错误:

【问题讨论】:

    标签: php codeigniter authentication


    【解决方案1】:

    您是否阅读了错误信息?

    你有一个 (`) 不应该是。

    更改此:WHERE q_author' = users.id 为:WHERE q_author = users.id

    【讨论】:

    • 是的,发布问题几秒钟后,我发现了错误:(SELECT (SELECT SUM(vote_score) FROM question_votes JOIN questions ON vote_question = q_id JOIN users ON q_author = users.id WHERE q_author = users.id) + (SELECT SUM(vote_score) FROM answer_votes JOIN answers ON vote_answer = a_id JOIN users ON a_author = users.id WHERE a_author = users.id)) AS rep
    • 有时我们的头脑会很累,以至于明显的路过......每个人都会发生 =)
    猜你喜欢
    • 2013-02-11
    • 1970-01-01
    • 2012-06-23
    • 2011-10-12
    • 2013-06-10
    • 1970-01-01
    • 2014-01-17
    • 2011-09-07
    • 2016-01-23
    相关资源
    最近更新 更多