Page 1 of 1

Mysql select with LIKE and php variable

Posted: 27 May 2016, 17:19
by mluci12
How can i create a %Like select where variable is a php variable.

Mysql select with LIKE and php variable

Posted: 27 May 2016, 17:57
by Admin
I think, like this sql:

Code: Select all

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

Mysql select with LIKE and php variable

Posted: 27 May 2016, 18:38
by mluci12
how can i put 2 col_name in this sql ?

Mysql select with LIKE and php variable

Posted: 27 May 2016, 18:43
by Admin
Simple, like this:

Code: Select all

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