简体   繁体   English

PHP仅返回其中带有特定单词的mysql条目(例如twitter)

[英]PHP to only return mysql entries with a certain word in it (like twitter)

Twitters search returns all statuses with the word used in the search query. Twitters搜索将返回所有状态以及搜索查询中使用的单词。 I'm just wondering how i could do this in PHP so it would only display the mysql entrys with that word in it? 我只是想知道如何在PHP中做到这一点,以便它仅显示带有该单词的mysql条目?

使用全文搜索或第三方软件,例如狮身人面像 ,solr,lucene,...

Use a while loop on your result resource after making the database connection and echo out all the records one by one. 建立数据库连接后,对结果资源使用while循环,并逐个回显所有记录。 Your query should look something like the one below depending on what the user entered. 您的查询应类似于以下查询,具体取决于用户输入的内容。 You should also echo at least a <br> between each loop! 您还应该在每个循环之间至少回显一个<br>

SELECT * FROM tweets WHERE text LIKE '%word%';

Will show you all the tweets with 'word' in it. 将向您显示所有带有“单词”的推文。


Edit: 编辑:

Since you are just trying to match on a word and not duplicate twitter's search algorithm, to get up and running the quickest use mysql's full text search. 由于您只是想在单词上进行匹配,而不是重复使用twitter的搜索算法,因此要快速起步并运行,请使用mysql的全文本搜索。 Thank you zerkms. 谢谢你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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