I have gotten myself into a tangled mess with quotes.
I am trying to do a like query that looks something like this
$myQuery = 'SELECT col1 , col2 from my_table WHERE col_value LIKE '%$my_string_variable%';
But this query would obviously give an error. What is the right syntax for this? I tried messing with double-quotes, but that didn't work either.
Combine double and single quotes.
$myQuery = "SELECT col1 , col2
FROM my_table
WHERE col_value LIKE '%$my_string_variable%'";
Although I prefer to protect my code against SQL Injection..
$myQuery = "SELECT col1 , col2
FROM my_table
WHERE col_value LIKE '%" . mysql_real_escape_string($my_string_variable) . "%'";
Surround the whole thing in double quotes.
$query = "SELECT col1 , col2 from my_table WHERE col_value LIKE '%$my_string_variable%'";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With