Php? Search function

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.