How to perform strictly SQL query that uses multiple values and searches all fields I'm trying to create what I would call an &quot;inclusive&quot; search and by that, I'm not referring to &quot;between&quot;. I have a snippet of code and it does what I need it to do but it's hacky and inefficient so I'm wanting to know if I can possibly do it with just SQL. I'm using a third party library called MysqliDb but if you want to forego phrasing your answer in that format, it's fine.
        if ($this-&gt;data != '') {
        $searchParams = explode(' ', trim($this-&gt;data));
        foreach ($searchParams as $s) {
            $this-&gt;db-&gt;orWhere('customer_name', '%'.$s.'%', 'like');
            $this-&gt;db-&gt;orWhere('customer_address', '%'.$s.'%', 'like');
            $this-&gt;db-&gt;orWhere('customer_city', '%'.$s.'%', 'like');
            $this-&gt;db-&gt;orWhere('customer_zip', '%'.$s.'%', 'like');
            $this-&gt;db-&gt;orWhere('customer_email1', '%'.$s.'%', 'like');
        }
        $this-&gt;db-&gt;having('customer_status', 'Active');
        $this-&gt;db-&gt;having('owner_id', $this-&gt;owner_id);
        $binaryArray = array_fill(0, sizeof($searchParams), 0);
        $results = $this-&gt;db-&gt;get('tblcustomers');
        $filtered = [];
        foreach ($results as $r) {
            $binaryArray = array_fill(0, sizeof($searchParams), 0);
            foreach ($binaryArray as $key=&gt;$b) {
                if (strpos(strtolower($r['customer_name']), strtolower($searchParams[$key])) !== false ||
              strpos(strtolower($r['customer_address']), strtolower($searchParams[$key])) !== false ||
              strpos($r['customer_city'], strtolower($searchParams[$key])) !== false ||
              strpos($r['customer_zip'], strtolower($searchParams[$key])) !== false ||
              strpos($r['customer_email1'], strtolower($searchParams[$key])) !== false
            ) {
                    $binaryArray[$key] = 1;
                }
            }
            if (!in_array(0, $binaryArray)) {
                $filtered[] = $r;
            }
        }
    } else {
        $this-&gt;db-&gt;where('owner_id', $this-&gt;owner_id);
        $this-&gt;db-&gt;having('customer_status', 'Active');
        $filtered = $this-&gt;db-&gt;get('tblcustomers');
    }

$this-&gt;data is an input box with possible search words separated by spaces so my intent is to split the value of the input box up based on that and perform a query that has to include all of the parameters. By that I mean, I can easily do a query where it retrieves every row with $this-&gt;data[0] or $this-&gt;data[1] but I want to exclude rows that don't actually have have all of the words in $this-&gt;data in one column or another.
What I have does that but it uses a lot of PHP and I'd rather keep the db querying to SQL exclusively.
Well I looked into the Full Text Search but found it a bit cumbersome to perform it on joined tables, additionally, it's not that efficient so I just cleaned up the function I have

public function findByFilterQuery($request)
{
    $dbFields = ['first_name', 'last_name', 'email_address', 'tt_group.name', 'tt_position.name', 'tt_division.name'];
    $params = isset($request['search']) ? explode(' ', trim($request['search'])) : [];
    $users = User::ArrayBuilder()-&gt;with('group')-&gt;with('position')-&gt;with('division');
    foreach ($params as $param) {
        foreach ($dbFields as $field) {
            $users-&gt;orWhere($field, '%'.$param.'%', 'like');
        }
    }
    $results = [];
    $request['page'] = isset($reqest['page']) ? $this-&gt;data['page'] : 1;
    $users = $users-&gt;paginate($request['page']);
    if (sizeof($params) &amp;&amp; $users) {
        foreach ($users as $user) {
            $binaryArray = array_fill(0, sizeof($params), 0);
            foreach ($params as $key=&gt;$param) {
                foreach ($dbFields as $dbColumn) {
                    $val = $user;
                    foreach (explode('.', $dbColumn) as $subColumn) {
                        $val = $val[$subColumn];
                    }
                    $val = strtolower($val);
                    $param = strtolower($param);
                    if (strpos($val, $param) !== false) {
                        $binaryArray[$key] = 1;
                    }
                }
            }
            if (!in_array(0, $binaryArray)) {
                $results[] = $user;
            }
        }
    }
    return sizeof($results) ? $results : $users;
}