Php+ajax real-time input automatic search matching method _php skills

Source: Internet
Author: User
Tags explode

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

The first method exploits the jquery autocomplete, the second uses jquery Ajax, and in fact, two of them are the same.

The easiest way to do this is to use the jquery AutoComplete method directly, as follows in the example.

In HTML, the code is as follows:

Copy Code code as follows:
<script src= "/js/v2/jquery.input_complete.js" type= "Text/javascript" ></script>
<link rel= "stylesheet" href= "/css/v2/jquery.input_complete.css" type= "Text/css"/>
<script type= "Text/javascript" >
$ (function () {
$ ("#abcc"). Bigautocomplete ({width:176,data:[{title: "The Wharf century Washington," Result: "5976898"},{title: "Kowloon Cang June Seal", Result: "5976896" },{title: "Zhoushan Zhu Jia Tsim Dong Sha Resort", Result: "5976895"},{title: "Guangsha Sky Capital Jazz Garden", Result: "5976893"},{title: "Greentown Jade Garden", Result: "5976892"},{ Title: "Jiangnan Ming Lou", Result: "5976890"},{title: "Shimao Riverside Garden", Result: "14869"}],callback:function (data) {
$ ("#s_loupan"). Val (Data.result);
}});
})
</script>
<input type= "text" id= "ABCC" class= "Sel_quy" autocomplete= "Off"/>

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

For example, the Orbolg, press T when not displayed, press O when the display, the following is the implementation of code, I am dizzy, testing is no problem, the code is as follows:

Copy Code code as follows:
Public Function Gwquery () {
if ($_post) {
$ZM = $_post[' data '];
$WZM = $zm. " %";
$b = M (' WPINDEXGW ');
if ($zm!= "T") {//Get the first letter is not 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 ']);//Get header 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 and the second letter and the first letter are the same, the case is case-sensitive here.
$narr [] = $val; Write array
}
}
}else{//processing the first letter is T, do not want the first word number 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;//Get the array label of the content that you want to remove.
}
}
}
$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 above query, that is, if it is the time to press T does not show.
foreach ($unnarr as $uval) {
Unset ($list [$uval]);
}
When}else{//is not pressing T, add the second first letter to the array of normal queries.
if (!emptyempty ($narr) &&!emptyempty ($list)) {//Take the same condition as normal itself is not empty.
$list = Array_merge ($narr, $list);//merge array.
}else if (Emptyempty ($list)) {//Normal query is empty. To see if there are any with the beginning, then 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, the difference is too much, the code is as follows:
Copy Code code 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 will help you with your PHP program design.

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.