09-21-2017, 10:57 AM
I have a problem with my database query and would like help getting it to work please.
Both of the code snippets above do not work.
I have a joined the posts table to the votes table, and I would like to only fetch rows where votes.content is "accept".
However each time I try to do so with the code above, that never happens, it fetches rows that say "accept" and don't say accept in the same query.
What is going on and how do I fix it?
PHP Code:
$acceptal = $this->db->select(array('posts.content', 'posts.id', 'posts.userid', 'votes.userid'))->join('users', 'posts.userid = users.id')->join('votes', "votes.questionid = $debate[id]", "users.id = votes.userid", 'votes.content = accept')->select(array('users.username','users.avatarpath'))
->get_where('posts', array('posts.questionid' => $debate['id'], 'posts.floor' => 0))
->get_where('votes', array('votes.content' => "accept"))
;
PHP Code:
$acceptal = $this->db->select(array('posts.content', 'posts.id', 'posts.userid', 'votes.userid'))->join('users', 'posts.userid = users.id')->join('votes', "votes.questionid = $debate[id]", "users.id = votes.userid", 'votes.content = accept')->select(array('users.username','users.avatarpath'))
->get_where('posts', array('posts.questionid' => $debate['id'], 'posts.floor' => 0, 'votes.content' => "accept"))
;
Both of the code snippets above do not work.
I have a joined the posts table to the votes table, and I would like to only fetch rows where votes.content is "accept".
However each time I try to do so with the code above, that never happens, it fetches rows that say "accept" and don't say accept in the same query.
What is going on and how do I fix it?