Welcome Guest, Not a member yet? Register   Sign In
Query Builder "Where" with Array
#6

If you have multiple values to compare, why are you not using whereIn()? Since you have multiple fields (brand and country), you'll have to add them to the query seperately. While where() concatenates multiple fields/values with " AND ", whereIn expects only one field. So you'll have to do multiple whereIn()s.

I haven't tested CI 4. My assumptions are based on my experience with CI 3.

As a side question, is there a general, common way to handle filtering in CI? If I have multiple (4+) fields to filter (using equals, NOT, IN, etc.), things get out of hand a little. Accessing the db object (and using corresponding methods) for each filter doesn't seem that practical. Especially if one filter modifies/cancels the previous one.

To get around this, I've created a helper select method. I create an array, something similar to this:

PHP Code:
[
    "select" => "staff.id, users.email, users.display_name, users.image, users.type",
    "from"   => "staff",
    "join"   => [
        ["users""users.id = staff.user_id"]
    ],
    "order_by" => "users.display_name",


and pass this to the helper select method. This makes modifying the query much easier. I get to pass the query only when it's done. Though this still has problems when doing filtering. There's no easy way to map/store/represent all where filters using an array. I just improve the helper method as problems arise.

I'd like to know how the community deals with this.
Reply


Messages In This Thread
Query Builder "Where" with Array - by IvanBell - 05-18-2020, 02:52 AM
RE: Query Builder "Where" with Array - by akinuri - 05-19-2020, 09:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB