doushao1087 2013-10-04 18:22
浏览 25

创建搜索字段

So i'm working on this site and i just added a search button. Everything works fine when i use a simple search query like

SELECT `student_id` FROM `student` WHERE `username` LIKE 'jo%' OR `firstname` LIKE 'jo%' OR `lastname` LIKE 'jo%' OR `surname` LIKE 'jo%' OR `email` LIKE 'jo%' 

This will return all id with a name that matches john from a database by looking at the fields 'username', firstname, lastname, and so on.

Th problem however is, when the user inserts a space between the search parameter (which in essence means he is searching a student by both names), the result is nothing.

I figured that this is because the it is looking for the search parameter (say, 'john doe') independently in each field.

How do i work around this.

  • 写回答

5条回答 默认 最新

  • dongyong6045 2013-10-04 18:25
    关注

    If you want to get into searching/matching across multiple columns, you really need to look into MySQL full text search capabilities. See this link for documentation to get you started:

    http://dev.mysql.com/doc/refman/5.5/en/fulltext-natural-language.html

    This will scale much better than trying to LIKE across a bunch of columns.

    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思