LIKE operator with $variable

Posted by skarama on Stack Overflow See other posts from Stack Overflow or by skarama
Published on 2009-12-03T22:56:38Z Indexed on 2010/04/07 1:23 UTC
Read the original article Hit count: 385

Filed under:
|
|
|

This is my first question here and I hope it is simple enough to get a quick answer!

Basically, I have the following code:

$variable = curPageURL();
$query = 'SELECT * FROM `tablename` WHERE `columnname` LIKE '$variable' ;

If I echo the $variable, it prints the current page's url( which is a javascript on my page)

Ultimately, what I want, is to be able to make a search for which the search-term is the current page's url, with wildcards before and after. I am not sure if this is possible at all, or if I simply have a syntax error, because I get no errors, simply no result!

I tried :

    $query = 'SELECT * FROM `tablename` WHERE `columnname` LIKE '"echo $variable" ' ;

But again, I'm probably missing or using a misplaced ' " ; etc.

Please tell me what I'm doing wrong!

© Stack Overflow or respective owner

Related posts about sql

Related posts about like-operator