0
如何選擇使用PHP搜索標籤的mysqli?如何選擇使用PHP搜索標籤的mysqli?
我有表:這樣
___________________________________________
|_id_|_______name_______|________tag________|
| 1 | dog | animal,pet,dog |
| 2 | donuts | food,donuts |
| 3 | BMW | car |
| 4 | football | sport |
| 5 | ferrari | car,supercar |
和選擇
$query = "SELECT * FROM test WHERE tag = '$_GET[tag]' order by id desc";
這是mysqli的PHP代碼測試然後,我通過這個網址
www.example.com/search_tag.php?tag=car
測試我的代碼,但它將只顯示行號3
,如何選擇顯示行號3
和5
?
更好地規範化您的數據。暫時你可以使用'FIND_IN_SET',比如'... WHERE FIND_IN_SET(your_input_tag,tag)> 0 ...'。必須爲你閱讀[**存儲分隔列表真的很糟糕嗎?**](http://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really -that-bad) – 1000111
像這樣'$ query =「SELECT * FROM test WHERE FIND_IN_SET($ _ GET ['tag'],tag)> 0 order by id desc」;'? –
甚至不打擾與此,修復數據庫結構 – nogad