简体   繁体   中英

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.

Are you sure that LIKE '$cuts%' is correct? I believe that it should be LIKE '%$cuts%'. In the way that you have written it, it will only find the products which start with the value of the $cuts

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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