Welcome Guest, Not a member yet? Register   Sign In
or_Like Question

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').

$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.

I'm not clear with what query you want to achieve...


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?


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?

The above outputs the following code when $match = new;
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.


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...
$sql = "SELECT * FROM (customer) "
       ."WHERE bb_id = '".$bb_id."' "
       ."AND (fname LIKE '%".$new."%' "
       ."OR lname LIKE '%".$new."%' "
       ."OR email LIKE '%".$new."%') "

Theme © iAndrew 2016 - Forum software by © MyBB