简体   繁体   English

根据参数php pdo从数据库中选择条目

[英]select entry from database based on parameter php pdo

it is hard for me to explain the question so i will just state a scenario: 我很难解释这个问题,所以我只说一种情况:

in my database the entry saved are door,do,dont,deed,did,doo and i type do in the search box to be used as parameter to search database so now the parameter i used for search is do . 在我的数据库中,保存的条目是door,do,dont,deed,did,doo并且我在搜索框中键入do作为搜索数据库的参数,所以现在用于搜索的参数是do

1.the question is, is it possible to search all the entries with the letter *do* in them i mean in my example the words *door,do,dont,doo* should be selected.

2.how can i do this kind of search

any suggestion is appreciated 任何建议表示赞赏

UPDATE: 更新:

something like an autocomplete select 像自动完成选择

A simple like query should do job 一个简单的类似查询应该起作用

select * from 'your table name' where 'column_name' like %do%

For More info 欲了解更多信息

And You should really really read documentations more clearly.(just an advice) 而且您确实应该更清楚地阅读文档。(只是一个建议)

You can use LIKE clause to perform this. 您可以使用LIKE子句执行此操作。

For example: 例如:

 SELECT column FROM table WHERE column LIKE do%

在您查询条件的地方使用LIKE运算符

  1. Yes you can: SQL: 是的,您可以:SQL:

      SELECT * FROM yourTableName where yourFieldName like 'do%' 
  2. I guess you want to implement a autosuggestion. 我想您想实施自动建议。 If this is the case than use jQuery to make Ajax calls to your Server. 如果是这种情况,则可以使用jQuery对服务器进行Ajax调用。 The script on the server gets the request with the letters in the searchbox, here 'do', excutes the SQL from 1. (you have to adapt with the letters you get) and response it to the website with the possible words, here door, do, dont... . 服务器上的脚本使用搜索框中的字母来获取请求,这里是“ do”,从1中提取SQL。(您必须使用所获取的字母进行修改),并使用可能的单词将其响应到网站,在这里,做,不要... Than the jQuery gets the response and builds from the possible words a list and displays it. 比jQuery获得响应并从可能的单词构建一个列表并显示它。

Hope this helps a bit. 希望这个对你有帮助。

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

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