Home > Software design >  How to create MULTIPLE LIKE query for the same column in codeigniter?
How to create MULTIPLE LIKE query for the same column in codeigniter?

Time:10-16

Let's say I want to get all rows in a text column that contain both of three words (word1, word2, word3)

so my sql would be

SELECT 
    *
FROM
    mytable
WHERE
    col_text LIKE '%word1%'
        AND col_text LIKE '%word2%'
        AND col_text LIKE '%word3%'

is there any and_like in codeigniter?

CodePudding user response:

Supplying three like() to the query builder will assume, by default AND for each:

$this->db
     ->from( "mytable" )
     ->like( "col_text", 'word1', 'both' )
     ->like( "col_text", 'word2', 'both' )
     ->like( "col_text", 'word3', 'both' );
  • Related