Mysql select with LIKE and php variable

Discuss coding issues, and scripts related to PHP and MySQL.
mluci12
Posts: 39

Mysql select with LIKE and php variable

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

Admin Posts: 805
I think, like this sql:

Code: Select all

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

mluci12 Posts: 39
how can i put 2 col_name in this sql ?

Admin Posts: 805
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