PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 6, 2022

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

 January 06, 2022     codeigniter, mysql     No comments   

Issue

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?


Solution

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


Answered By - MackieeE
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing