Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8726723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:18:23+00:00 2026-06-13T08:18:23+00:00

So I admit the title is a bit, confusing, I apologize cause I have

  • 0

So I admit the title is a bit, confusing, I apologize cause I have no idea what to make it, so open to suggestions there. Anyway on to the actual question. I have a query, works fine for the most part, however I am still yielding some wrong results. Understandably so as well. As that is how this is forming the query. To many ands and to many ors loosely strung together. What I need to do is wrap a set of the where clauses in ( ) then have an and then the remaining set of clauses in another ( ) I have no idea if that makes sense to anyone.

Basically if I were hand typing the query outright it’d look something like..

select * from my_table
where (cond1 = this and cond2 = that) 
and (cond2 != something or cond3 > other)

Not really sure how to accomplish that using codeigniter’s active record. What I currently have is.

$this->db->select('user_event_invite.*, game_bridge.*, user_event.*, user_event.location as bizfo')
->from('user_event')
->join('game_bridge', 'user_event.gID = game_bridge.gID')
->join('user_event_invite', 'user_event_invite.eID = user_event.eID')
->where('user_event_invite.friendID', $mID)
->where('user_event.isactive', 0)
->where('user_event_invite.isactive', 0)
->where('user_event.ends >=', $this->genfunc->unixToMySQL(time()))
->where('user_event.ends !=', '0000-00-00 00:00:00')
->or_where('yes > ', 0)
->or_where('no > ', 0)
->or_where('maybe > ', 0);

but what I am ultimately wanting is all these specific clauses in one group..

->where('user_event_invite.friendID', $mID)
->where('user_event.isactive', 0)
->where('user_event_invite.isactive', 0)
->where('user_event.ends >=', $this->genfunc->unixToMySQL(time()))
->where('user_event.ends !=', '0000-00-00 00:00:00')

then combine that group with and AND to this other group.

->or_where('yes > ', 0)
->or_where('no > ', 0)
->or_where('maybe > ', 0);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:18:24+00:00Added an answer on June 13, 2026 at 8:18 am

    So, CodeIgniter doesn’t support “wrapping” your OR and AND SQL statements, not using its abstraction layer at least. Mixing OR and AND statements is not recommended by CodeIgniter.

    You can try understanding the query that your executing with $this->db->last_query()

    You can also try this sub-query library to see if it can help you out:
    http://labs.nticompassinc.com/CodeIgniter-Subqueries/

    Or you may just have to use some RAW SQL in your case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'll admit the title is a bit confusing but it was hard to come
I will have to admit the title of this question sucks... I couldn't get
The title is so confusing, I admit it - if you want to change
Okay, that title was an attention grabber. I'll admit that. Now to the question!
The original question: The title of this question might be a bit clumsily phrased,
OK, I admit that the title is a bit misleading. I'm braindead currently, so
I admit I'm little bit poor in functions in mathematics. But I'm in real
I admit that I have almost none experience of unittesting. I did a try
Background I admit, this question stems from an ultimate lack of deep understanding of
OK so I admit right off the top that this is a bit screwy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.