doudeng9425 2013-11-03 16:10
浏览 17
已采纳

使用MySQL搜索多个术语

I'm looking for the most effective way to do a search with select with multiple terms in mysql and php. A basic select for a single key word in mysql can look like this;

select * from <table> where (Message like '%term%' or Subject like '%term%');

Works fine for a single term. For multiple terms, the suggestions that I've seen is that each word that's posted from a form should be sent to an array and the contents should be processed with a For loop. I'm wondering if there's a way to do it on the mysql side? My suspicion is that there isn't, but it doesn't hurt to ask.

  • 写回答

1条回答 默认 最新

  • doukenqiong0588 2013-11-03 16:19
    关注

    You could do it strictly using MySQL, with lots of calls to MID() and so on, but it would be much more complex than in PHP. In fact, you would almost certainly need a stored procedure, unless you were certain that the query only involved up to a fixed number of terms (e.g., between 1 and 10 words).

    PHP will make this much simpler, and you can also use prepared statements to make things more secure. See this discussion.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 QTableWidget重绘程序崩溃
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding