Php? The search function searches data that meets the search criteria.
1. how to implement this function?
2. if there are too many data and the search is slow, how can we solve these problems ??
Reply to discussion (solution)
1. splice the received data into a conditional statement
2. using indexes to improve efficiency
Which eldest brother can give an example?
1. Generate SQL where statement based on the conditions
2. add an index to the fields to be searched.
For example, the database has three fields to search for, a B c.
First, indexes must be added to all three fields.
The query statement is as follows:
$ A = $ _ POST ['A'];
$ B = $ _ POST ['B'];
$ C = $ _ POST ['c'];
$ Where = array ('1 = 1 ');
If ($ ){
$ Where [] = "a = '". $ ."'";
}
If ($ B ){
$ Where [] = "B = '". $ ."'";
}
If ($ c ){
$ Where [] = "c = '". $ ."'";
}
$ Sqlstr = "select * from table where". implode ('and', $ where );
// Execute the query.
?>
In fact, there are only two points. Generate the corresponding SQL statement and splice it. create an index for the search field. These two points should meet your requirements!
Add an index to the field to be searched
What index should I add ??
Add an index to the field to be searched
What index should I add ??
It is better to search for this keyword.
In addition, do you have not implemented this function yet? Don't worry about efficiency first.