The table hashtags contains the words bla,bla2,bla3

 "SELECT * FROM data WHERE hashtags = '$tag' ORDER BY id DESC" 

does not display anything, as it is looking for a full line. How to create a request and what else is needed for this?

  • and also, in php, do not write variables inside quotes, this reduces readability and speed of execution. - IVsevolod

2 answers 2

Hello, hashtags is a field (column)). If I understood correctly, here is the solution:

 SELECT * FROM `data` WHERE `hashtags` like '%".$tag."%' ORDER BY `id` DESC 

    For example, hashtags is a column. For this task, full-text search algorithms are used. In the worst case, you can search by SELECT * FROM data WHERE hashtags LIKE "' . $tag . '%" ORDER BY id DESC . In no case can not use like '%".$tag."%' , This is a very heavy query, because indexes will not be used.

    • But why the nivkoem case, in many source codes of good engines, such a brainchild is used, about optimization ... It plays only for fat tables ;-) - Node_pro
    • this approach is not used in good engines - Nikita Tkachenko