• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
or_Like Question

#1
[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.

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

#3
[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

#4
[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?

#5
[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

#6
[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."%') "


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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