[英]How to find a text field is existing in a MYSQL table
I want to store user Search Queries in to MYSQL databse. 我想将用户搜索查询存储在MYSQL数据库中。 I have created a Search_Queries field in mysql table and it type is text , Collation is utf8_general_ci .
我在mysql表中创建了一个Search_Queries字段,它的类型是text ,归类是utf8_general_ci 。
If the search word is exists in the table, then update the Search_Count++ else insert the search word into the table 如果表中存在搜索词,则更新Search_Count ++,否则将搜索词插入表中
I have used for find existing 我已经用来寻找现有的
**SELECT ID FROM search_details WHERE Search_Query='keyword' LIMIT 1**
if it return empty then insert the keyword 如果返回空,则插入关键字
**INSERT INTO search_details SET Search_Query='".$SearchQuery."',Search_Count=1"**
else update the search_count field 否则更新search_count字段
UPDATE search_details SET Search_Count='".$Search_Count."' WHERE ID='".$ID."'
my problem is if the Search Query is not exists in the table 我的问题是如果表中不存在搜索查询
**SELECT ID FROM search_details WHERE Search_Query='keyword' LIMIT 1**
this returns with last row instead of NULL 这将返回最后一行而不是NULL
successfully insert the Search Query into the table and search count set as to 2 成功将“搜索查询”插入表并将搜索计数设置为2
basically , isnt that what you wanted to do in here 基本上,不是您想在这里做什么
INSERT INTO search_details SET Search_Query='".$SearchQuery."',Search_Count=1"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.