CodeIgniter Forums
or_Like Question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: or_Like Question (/showthread.php?tid=40712)



or_Like Question - El Forum - 04-16-2011

[eluser]DanTheMan[/eluser]
Dear Community,

Please could you provide me some information with the following problem:

I am trying to use the or)like function but I need to be able to say or_like('column', $match AND 'anothercolum' = 'xx').

Code:
$this->db->where('xx_id', $this->config->item('xx_id'));
        $this->db->like('fname', $match);
        $this->db->or_like('lname', $match);
        $this->db->or_like('email', $match);

Please could someone give me a hint to the correct syntax to adapt this, so each of the like clauses check the xx_id = config->item xx_id.

I am using CI 2.0.

Thanks in advanced.


or_Like Question - El Forum - 04-16-2011

[eluser]toopay[/eluser]
I'm not clear with what query you want to achieve...


or_Like Question - El Forum - 04-16-2011

[eluser]DanTheMan[/eluser]
Hi,

Sorry. I must have not explained well.

I want check my $match var to get matches in fname or lname or email in the table. However I need to make sure for each of the likes that the bb_id is equal to $this->config->item('bb_id').

Does that make more sense?

Thanks,
Dan


or_Like Question - El Forum - 04-16-2011

[eluser]toopay[/eluser]
Why you need to check each of that?
I see on your code above, you're already put "bb_id is equal to $this->config->item(‘bb_id’)" rules, so it not necessary anymore...
Are you didn't get the expected result from your query above?


or_Like Question - El Forum - 04-16-2011

[eluser]DanTheMan[/eluser]
The above outputs the following code when $match = new;
Code:
SELECT * FROM (`customer`) WHERE `bb_id` = '28' AND `fname` LIKE '%new%' OR `lname` LIKE '%new%' OR `email` LIKE '%new%' LIMIT 10

The intended output would be that it displays only where the bb_id is equal to 28. However, the real output will display all the records in the database with any bb_id that matches new.

Thanks,
Dan


or_Like Question - El Forum - 04-16-2011

[eluser]toopay[/eluser]
I'm affraid, that you must write the query in a string, because ActiveRecord in CodeIgniter not supporting sub-query (yet). I suspect, you must be need query like...
Code:
$sql = "SELECT * FROM (customer) "
       ."WHERE bb_id = '".$bb_id."' "
       ."AND (fname LIKE '%".$new."%' "
       ."OR lname LIKE '%".$new."%' "
       ."OR email LIKE '%".$new."%') "