Welcome Guest, Not a member yet? Register   Sign In
Problems creating an SQL query
#1

(This post was last modified: 01-05-2019, 04:02 AM by desbest.)

Hello I'm having problems with an SQL query I'm trying to do with CodeIgniter


Code:
$comments = $this->db
    ->select(array('posts.content', 'posts.id', 'posts.userid', 'posts.postid', 'posts.nodeview', 'posts.questionid','posts.groupid'))->join('users', 'posts.userid = users.id')
    ->select(array('users.username','users.avatarpath'))->order_by('posts.datetimenumber', 'DESC')
    ->limit(20, $page)
    ->get_where('posts', array('posts.userid' => $user['id'],'posts.nodeview !=' => "article",'posts.nodeview !=' => "pm" /*, 'posts.floor >' => 0 */  ) )
    ;


The problem is that I am using 2 NOT queries on posts.nodeview, and only one of them is being applied.

How can I make the query work?
Reply
#2

(This post was last modified: 01-04-2019, 10:55 AM by jreklund.)

I can only see one of them: 'posts.nodeview !='

Are you meaning this?
'posts.nodeview ='
Reply
#3

(This post was last modified: 01-04-2019, 12:53 PM by Wouter60.)

PHP Code:
$this->db
->select('p.content,p.id,p.userid,p.postid,p.nodeview,p.questionid,p.groupid,u.username,u.avatarpath')
->
from('posts p')
->
join('users u''p.userid = u.id')
->
where('p.userid',$user['id'])
->
where_not_in('p.nodeview', array('article','pm'))
->
order_by('p.datetimenumber''DESC')
->
limit(20,$page);
$query $this->db->get();
if (
$query->num_rows() > 0) {
 return 
$query->result();
}
else {
 
  return FALSE;


This will select the records where posts.nodeview is not 'article' and not 'pm'.
Is that what you need?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB