hery
hery

Reputation: 49

How to create MULTIPLE LIKE query for the same column in codeigniter?

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?

Upvotes: 1

Views: 167

Answers (1)

MackieeE
MackieeE

Reputation: 11872

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

Upvotes: 1

Related Questions