• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Active Record: how do I combine two or_like with an AND between them?

#1
[eluser]sparbier[/eluser]
Hi all,
I need to run a query that takes inputs from two arrays (from post data, don't know beforehand how many elements are given), and looks for the elements of these arrays in two separate fields in my database. So this is what I did:
Code:
if (isset($_POST['region'])) {
        foreach ($_POST['region'] as $r)  {
            // put the searched id between commas before searching for it in the string, in order not to e.g. find a 4 contained in 42 but only ,4,
            $searchstring = ','. $r .',';
            $this->db->or_like('regions', $searchstring);
        }
    }
    if (isset($_POST['instrument'])) {  
        foreach ($_POST['instrument'] as $i)  {
            $searchstring = ','. $i .',';
            $this->db->or_like('instruments', $searchstring);
        }
    }
The issue now is, that while I do want the LIKE statements within each of the two criteria be linked with OR, the two criteria must be linked with AND.

Is there any way to achieve this with Active Records?


Messages In This Thread
Active Record: how do I combine two or_like with an AND between them? - by El Forum - 11-29-2008, 05:52 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.