Php + ajax code 1 in the google drop-down box-PHP source code

Source: Internet
Author: User
Ec (2); php + ajax code 1 in the google drop-down box. Here, the php code & lt ;? Phpheader (Content-Type: texthtml; charsetutf-8); require (.... admin1_dedb_conf.php); if ($ _ POST [add]) {& nbsp; $ keywordtrim ($ _ script ec (2); script

Php + ajax is similar to google drop-down box code 1. php code here

Header ('content-Type: text/html; charset = UTF-8 ');
Require ('../admin/include/db_conf.php ');
If ($ _ POST ['add']) {
$ Keyword = trim ($ _ POST ['keyword']);
If (empty ($ keyword )){
Header ("LOCATION: suggest.html ");
Exit;
}
$ Db = db_connect ();
$ Db-> query ("set names 'gb2312 '");
$ SQL = "select * from suggest where keyword = '$ keyword '";
If ($ db-> query ($ SQL)-> num_rows> 0 ){
Header ("LOCATION: suggest.html ");
Exit;
}
$ Num = rand (15,200 8 );
$ SQL = "insert into suggest values (NULL, '$ keyword', $ num )";
$ Db-> query ($ SQL );
$ Db = NULL;
Header ("LOCATION: suggest.html ");
Exit;
}
$ Keyword = $ _ POST ['keyword'];
If (empty ($ keyword )){
Echo 'null ';
Exit;
}
$ Db = db_connect ();
$ Db-> query ("set names 'utf8 '");
$ SQL = "select * from suggest where keyword REGEXP '^ $ keyword' order by id desc limit 0, 15 ";
$ Result = $ db-> query ($ SQL );
If ($ result-> num_rows <1 ){
Echo 'null ';
Exit;
}
$ Arr = array ();
While ($ rows = $ result-> fetch_object ()){
$ Keyword = $ rows-> keyword;
$ Arr [] = "['$ keyword',' $ rows-> num ". iconv ('gb2312', 'utf-8', 'result '). "']";
}
$ Arr = '['. implode (',', $ arr). ']';
Echo $ arr;
?>

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.