Ivanka Todorova
Ivanka Todorova

Reputation: 10219

SQL + Ion Auth + CodeIgniter?

I have the following 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

and I want it to be added here (Ion Auth's method):

    $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"
            )
        );

but I get the followin error: my error

Upvotes: 0

Views: 422

Answers (1)

user745235
user745235

Reputation:

Did you read the error message?

You have a (`) where shouldn't be any.

Change this: WHERE q_author' = users.id for this: WHERE q_author = users.id

Upvotes: 1

Related Questions