热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

多个关键字搜索脚本需要一些专家输入-multiplekeywordsearchscriptneedssomeexpertinput

Ihavebeenwrittingakeywordsearchscriptbasedonthistutorial:http:www.hackosis.com200711

I have been writting a keyword search script based on this tutorial: http://www.hackosis.com/2007/11/06/howto-simple-search-engine-with-php-and-mysql/

我一直在编写基于本教程的关键字搜索脚本:http://www.hackosis.com/2007/11/06/howto-simple-search-engine-with-php-and-mysql/

Like some of the commenters mentioned, the script only ends up returning results based on the last word in the search terms. So I have also tried to implement one of the suggestions from another user, but now I seem to only be able to get results based on the first search term.

与提到的一些评论者一样,脚本最终只会根据搜索字词中的最后一个字返回结果。所以我也试图实现其他用户的一个建议,但现在我似乎只能根据第一个搜索词得到结果。

The code for my script can be found here: http://php.pastebin.com/m7759afd3

我的脚本代码可以在这里找到:http://php.pastebin.com/m7759afd3

My print_r for the results looks like this:

我的print_r结果如下:

SELECT * FROM blog WHERE blog_title LIKE '%barry%' OR blog_content LIKE '%barry%' AND blog_title LIKE '%child%' OR blog_content LIKE '%child%' AND blog_title LIKE '%help%' OR blog_content LIKE '%help%' ORDER BY blog_title

SELECT * FROM links WHERE link_title LIKE '%barry%' OR link_desc LIKE '%barry%' AND link_title LIKE '%child%' OR link_desc LIKE '%child%' AND link_title LIKE '%help%' OR link_desc LIKE '%help%' ORDER BY link_title

SELECT * FROM pages WHERE page_title LIKE '%barry%' OR page_content LIKE '%barry%' AND page_title LIKE '%child%' OR page_content LIKE '%child%' AND page_title LIKE '%help%' OR page_content LIKE '%help%' ORDER BY page_title

Thank you for any help you might be able to offer.

感谢您提供的任何帮助。

2 个解决方案

#1


3  

If you want to return results that contain any of the keywords, then replace all the AND with OR.

如果要返回包含任何关键字的结果,请将所有AND替换为OR。

If you do this, then your db will check if any of the keywords exist in any of the columns of the table.

如果这样做,那么您的数据库将检查表中任何列中是否存在任何关键字。

Hence your final query would be read by the DB server like this:

因此,您的最终查询将由DB服务器读取,如下所示:

SELECT * FROM blog WHERE blog_title LIKE '%barry%' OR blog_content LIKE '%barry%' OR blog_title LIKE '%child%' OR blog_content LIKE '%child%' OR blog_title LIKE '%help%' OR blog_content LIKE '%help%' ORDER BY blog_title

and should return all that records that have the keywords (barry, child, help) in any column (blog_title, blog_content).

并且应该在任何列(blog_title,blog_content)中返回所有具有关键字(barry,child,help)的记录。

Hope this helps.

希望这可以帮助。

#2


1  

The AND operator has a higher precedence than OR, so if you want to return results that contain all of the keywords you need to add parentheses as follows:

AND运算符的优先级高于OR,因此如果要返回包含所有关键字的结果,则需要添加括号,如下所示:

  SELECT * FROM blog
  WHERE (blog_title LIKE '%barry%' OR blog_content LIKE '%barry%')
    AND (blog_title LIKE '%child%' OR blog_content LIKE '%child%')
    AND (blog_title LIKE '%help%' OR blog_content LIKE '%help%')
  ORDER BY blog_title

推荐阅读
  • PHP 编程疑难解析与知识点汇总
    本文详细解答了 PHP 编程中的常见问题,并提供了丰富的代码示例和解决方案,帮助开发者更好地理解和应用 PHP 知识。 ... [详细]
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • 本文详细介绍了如何使用 Yii2 的 GridView 组件在列表页面实现数据的直接编辑功能。通过具体的代码示例和步骤,帮助开发者快速掌握这一实用技巧。 ... [详细]
  • 本文介绍了在Windows环境下使用pydoc工具的方法,并详细解释了如何通过命令行和浏览器查看Python内置函数的文档。此外,还提供了关于raw_input和open函数的具体用法和功能说明。 ... [详细]
  • 使用Vultr云服务器和Namesilo域名搭建个人网站
    本文详细介绍了如何通过Vultr云服务器和Namesilo域名搭建一个功能齐全的个人网站,包括购买、配置服务器以及绑定域名的具体步骤。文章还提供了详细的命令行操作指南,帮助读者顺利完成建站过程。 ... [详细]
  • 在维护公司项目时,发现按下手机的某个物理按键后会激活相应的服务,并在屏幕上模拟点击特定坐标点。本文详细介绍了如何使用ADB Shell Input命令来模拟各种输入事件,包括滑动、按键和点击等。 ... [详细]
  • 根据最新发布的《互联网人才趋势报告》,尽管大量IT从业者已转向Python开发,但随着人工智能和大数据领域的迅猛发展,仍存在巨大的人才缺口。本文将详细介绍如何使用Python编写一个简单的爬虫程序,并提供完整的代码示例。 ... [详细]
  • 本题探讨如何通过最大流算法解决农场排水系统的设计问题。题目要求计算从水源点到汇合点的最大水流速率,使用经典的EK(Edmonds-Karp)和Dinic算法进行求解。 ... [详细]
  • 优化局域网SSH连接延迟问题的解决方案
    本文介绍了解决局域网内SSH连接到服务器时出现长时间等待问题的方法。通过调整配置和优化网络设置,可以显著缩短SSH连接的时间。 ... [详细]
  • 本文探讨了2012年4月期间,淘宝在技术架构上的关键数据和发展历程。涵盖了从早期PHP到Java的转型,以及在分布式计算、存储和网络流量管理方面的创新。 ... [详细]
  • 本文介绍了如何利用JavaScript或jQuery来判断网页中的文本框是否处于焦点状态,以及如何检测鼠标是否悬停在指定的HTML元素上。 ... [详细]
  • 本文详细介绍了如何使用PHP检测AJAX请求,通过分析预定义服务器变量来判断请求是否来自XMLHttpRequest。此方法简单实用,适用于各种Web开发场景。 ... [详细]
  • Hadoop入门与核心组件详解
    本文详细介绍了Hadoop的基础知识及其核心组件,包括HDFS、MapReduce和YARN。通过本文,读者可以全面了解Hadoop的生态系统及应用场景。 ... [详细]
  • 使用Pandas高效读取SQL脚本中的数据
    本文详细介绍了如何利用Pandas直接读取和解析SQL脚本,提供了一种高效的数据处理方法。该方法适用于各种数据库导出的SQL脚本,并且能够显著提升数据导入的速度和效率。 ... [详细]
  • 在现代Web应用中,当用户滚动到页面底部时,自动加载更多内容的功能变得越来越普遍。这种无刷新加载技术不仅提升了用户体验,还优化了页面性能。本文将探讨如何实现这一功能,并介绍一些实际应用案例。 ... [详细]
author-avatar
Mr_ZERO0000000
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有