简体   繁体   English

mysql 中更高效的查询

[英]More efficient query in mysql

I want to know how do they do a query with only one textbox in the page, but the current text in the text box can be used as a parameter for the query.我想知道他们如何在页面中仅使用一个文本框进行查询,但是文本框中的当前文本可以用作查询的参数。 I'm currently using the query below but I don't think I'm getting the desired results, is there anything wrong with my query?我目前正在使用下面的查询,但我认为我没有得到想要的结果,我的查询有什么问题吗?

$result1=query_database("SELECT * FROM prod_table WHERE CATEGORY LIKE '$cuts%' OR PRODUCT LIKE '$cuts%' OR P_DESC LIKE '$cuts%' ", "onstor", $link);

?>


<?php

if(mysql_num_rows($result1)==0){

}else{

How to do this kind of query better.如何更好地进行此类查询。

如果query_database不是您定义的

mysql_query("SELECT * FROM prod_table WHERE CATEGORY LIKE '$cuts%' OR PRODUCT LIKE '$cuts%' OR P_DESC LIKE '$cuts%' ", "onstor", $link);

Add indexes for each of the 3 fields, CATEGORY,PRODUCT,P_DESC and it should run much faster.为 3 个字段 CATEGORY、PRODUCT、P_DESC 中的每一个添加索引,它应该运行得更快。

Are you sure that LIKE '$cuts%' is correct?你确定 LIKE '$cuts%' 是正确的吗? I believe that it should be LIKE '%$cuts%'.我相信它应该像'%$cuts%'。 In the way that you have written it, it will only find the products which start with the value of the $cuts按照您编写的方式,它只会找到以 $cuts 的值开头的产品

在 $cut 之前使用 % 并转义此查询很好

 $result1=query_database("SELECT * FROM prod_table WHERE CATEGORY LIKE '%$cuts%' OR PRODUCT LIKE '%$cuts%' OR P_DESC LIKE '%$cuts%' ", "onstor", $link);

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

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