[英]mysql - find match in comma seperated text field
I am having problems with output from my (MySQL) database. 我的(MySQL)数据库输出出现问题。
attractionData database 吸引力数据数据库
id | tags
-------------------------------------
1 | castle a, castle b, fakecastle c
2 | museum a, fakemuseum b, museum c
...
And on a site I have an input field, which has autoSuggest function. 在站点上,我有一个输入字段,该字段具有autoSuggest功能。 So in my jQuery I have an .keyup event, which send data to ajax file, and the ajax file outputs the list of suggestions (autosuggest).
因此,在我的jQuery中,我有一个.keyup事件,该事件将数据发送到ajax文件,而ajax文件输出建议列表(自动建议)。
So now if I type in the input "castle a..." it will output the "1" (im outputting the id). 因此,现在如果我输入输入“ castle a ...”,它将输出“ 1”(即输出id)。 And if i type in "museum a" it will return "2".
如果我输入“博物馆a”,它将返回“ 2”。
So my question is... Is it somehow possible that if I would type in "fakecastle" that it would return "1"? 所以我的问题是...如果我键入“ fakecastle”,是否有可能返回“ 1”? I know this could be done with the
explode(',', $string)
. 我知道这可以通过
explode(',', $string)
。
I've been messing around with FIND_IN_SET(), but I somehow didn't achieve the result I wanted. 我一直在搞弄FIND_IN_SET(),但是我不知何故没有达到我想要的结果。 So I am still stucked with
所以我仍然坚持
mysql_query("SELECT tags FROM attractionData WHERE (tags LIKE '$search%') ")
$search = text from the input field. mysql_query("SELECT tags FROM attractionData WHERE (tags LIKE '$search%') ")
$ search =来自输入字段的文本。
EDIT 编辑
if(isset($_POST['search']) == true && empty($_POST['search']) == false){
$search = $_POST['search'];
$search = mysql_real_escape_string($search);
$query = mysql_query("SELECT tags FROM attractionData WHERE (tags LIKE '$search%') ")
while(($row = mysql_fetch_assoc($query)) !== false){
echo "<li class='auto'>".$row['friendEmail'] ."</li>";
}
Any help would be appreciated 任何帮助,将不胜感激
Ty, Sebastian Ty,塞巴斯蒂安
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.