Mysql select with LIKE and php variable

mluci12
Posts: 39

Mysql select with LIKE and php variable

How can i create a %Like select where variable is a php variable.

Admin
I think, like this sql:

Code: Select all

$varnm ='value'; $sql = "SELECT * FROM table_name WHERE col_name LIKE '%$varnm'"; 

mluci12
how can i put 2 col_name in this sql ?

Admin
Simple, like this:

Code: Select all

$varnm ='value'; $sql = "SELECT * FROM table_name WHERE col_1 LIKE '%$varnm' OR col_2 LIKE '%$varnm'"; 

Similar Topics