简体   繁体   中英

mySQL Like $query - Using a GET variable as the %LIKE% value

I am using a mySQL query which currently looks for just one value in this as such;

 "SELECT * FROM $usertable WHERE tabID LIKE '%spotlight%'";

this sits on index.php and this works great, however I would like the search value "spotlight" not to be hard coded, but so it is achieved from the URL

So when I go to

index.php?type=spotlight

ill get spotlights. and when I go to

index.php?type=lamps

I will get lamps

I have player around with this and at I am sure its something like this which I have been trying to make work...

$product_type = $_GET['type'];

       //*    and then lower down where the query sits *\\

"SELECT * FROM $usertable WHERE tabID LIKE '%$product_type%'";

but it really didn't like this and eded up showing all values for the $usertable

Any help would be greatly appreciated

Regards

Henry

"SELECT * FROM $usertable WHERE tabID LIKE '$type'";

尽管更改了搜索条件,但必须删除%,但必须完全包含该技巧。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM