Php+ajax real-time input automatic search matching method, Ajax automatic search _php tutorial

Source: Internet
Author: User

Php+ajax real-time input automatic search matching method, Ajax automatic search


The example of this paper describes the method of Php+ajax real input automatic search matching to share for everyone's reference. The specific analysis is as follows:

The first approach uses jquery AutoComplete, and the second uses jquery Ajax, in fact two of them are similar.

The simplest way is to use the jquery AutoComplete method directly, as shown in the example.

In HTML, the code is as follows:
Copy the Code code as follows:



The purpose of this article is to have a title with the first letter of the letter T, instead of the first letter of the second text search.

For example the ORBOLG, do not display when the T, press O when the display, the following is the implementation of code, I am dizzy, the test is no problem, the code is as follows:
Copy CodeThe code is as follows: Public function gwquery () {
if ($_post) {
$ZM = $_post[' data '];
$WZM = $zm. " %";
$b = M (' WPINDEXGW ');
if ($zm! = "T") {//Gets the first letter is not the time of T
$list 1 = $b->where ("Gwstatus=1 and gwname like '% $ZM% '")->order ("Time desc")->select ();//Query
$narr =array ();
foreach ($list 1 as $key = = $val) {
$CT 2 = Explode ("", $val [' gwname ']);//Gets the title split into an array.
$szm =strtolower (substr ($ct 2[1],0,1)); Get first letter and lowercase
if ($ct 2[0]== "the" && $szm = = $zm) {//If the first character is the same as the second letter and the first letter is submitted, the case is the same here.
$narr [] = $val; Write an array
}
}
}else{//processing the first letter is T, do not want the first word of the display in the list.
$list 1 = $b->where ("Gwstatus=1 and gwname like ' $wzm '")->order ("Time desc")->select ();
foreach ($list 1 as $key = = $val) {
$CT 2 = Explode ("", $val [' gwname ']);
if ($ct 2[0]== "the") {
$unnarr [] = $key;//Gets the array label of the content to be removed, if the condition is met.
}
}
}
$list = $b->where ("Gwstatus=1 and gwname like ' $wzm '")->order ("Time desc")->select ();//Normal query.
if ($zm = = "T") {//processing when the first letter is T, remove the contents of the query above, that is, if it is not displayed by pressing T.
foreach ($unnarr as $uval) {
Unset ($list [$uval]);
}
}else{//when not pressed, add the second first letter to the array of normal queries.
if (!emptyempty ($narr) &&!emptyempty ($list)) {//with the qualifying condition itself is not empty.
$list = Array_merge ($narr, $list);//merge arrays.
}else if (Emptyempty ($list)) {//Normal query is empty. See if there are any with the beginning, merge
$list =array ();
$list = Array_merge ($narr, $list);
}
}
if ($list) {
$this->ajaxreturn ($list, ' success ', 1);
}else{
$this->error ("Bestiary not Found.");
}
}
}
Compared to the previous code, there are too many differences, the code is as follows:
Copy CodeThe code is as follows: Public function Gwquery1 () {//before backup.
if ($_post) {
$ZM = $_post[' data '];
$WZM = $zm. " %";
$b = M (' WPINDEXGW ');
$list = $b->where ("Gwstatus=1 and gwname like ' $wzm '")->order ("Time desc")->select ();
Dump ($list);
if ($list) {
$this->ajaxreturn ($list, ' success ', 1);
}else{
$this->error ("Bestiary not Found.");
}
}
}

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/933607.html www.bkjia.com true http://www.bkjia.com/PHPjc/933607.html techarticle Php+ajax Real-time input automatic search matching method, Ajax auto-Search This article describes the Php+ajax real input automatic search matching method to share to everyone for your reference. The specific analysis is as follows ...

  • Related Article

    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.