Ajax search prompt

Source: Internet
Author: User
Ajax search tips: Read the ajax search tips: database table: copy the content to the clipboard code: CREATETABLE 'xqbar '. 'suggest '('id' INTNOTNULLAUTO _ INCREMENT, 'title' VARCHAR (100) NOTNULL, 'hits' INTNOTNULLD

Database Table: copy content to clipboard
Code:

Create table 'xqbar'. 'suggest '(
'Id' int not null AUTO_INCREMENT,
'Title' VARCHAR (100) not null,
'Hits 'Int not null default '0 ',
Primary key ('id ')
) ENGINE = InnoDB

Insert into suggest (title, hits) values ('xqbar. com', 100 );
Insert into suggest (title, hits) values ('www .xqbar.com ', 410 );
Insert into suggest (title, hits) values ('http: // xqbar.com ', 700 );
Insert into suggest (title, hits) values ('mail: xqbar.com ', 200 );
Insert into suggest (title, hits) values ('ftp: xqbar.com ', 100 );
Insert into suggest (title, hits) values ('http: // www.xqbar.com ', 70) search. php
(I am not familiar with php too soon. if the following php is still looking at your fingers)
The returned information string must be xxx1 | xxx2 $200 | copy the content before and after 100 to the clipboard.
Code:

If ($ _ GET ["action"]! = ''){
# Retrieving keywords entered by users
$ Keyword = $ _ GET ["keyword"];
# Filter keywords
$ Keyword = str_replace ("[", "[[]", $ keyword );
$ Keyword = str_replace ("&", "[&]", $ keyword );
$ Keyword = str_replace ("%", "[%]", $ keyword );
$ Keyword = str_replace ("^", "[^]", $ keyword );
# Connecting to a database
$ Conn = mysql_connect ("localhost", "xqbar", "xqbaradmin ");
# Selecting a database
@ Mysql_select_db ("xqbar") or die ('sorry ');
Mysql_query ('set names utf-8 ');
# Query statement
$ SQL = "select title, hits from suggest where title like '%". $ keyword. "% 'Order by hits desc limit 10 ";
$ Result = mysql_query ($ SQL );
# Obtain the query result cyclically and return a string
# Result 1 | result 2 $ result 1 clicks | result 2 clicks
If ($ result ){
$ I = 1; $ title = "'; $ hits = "';
While ($ row = mysql_fetch_array ($ result, MYSQL_BOTH ))
{
$ Title = $ title. $ row ['title'];
$ Hits = $ hits. $ row ['hits '];
If ($ I {
$ Title = $ title. "| ";
$ Hits = $ hits. "| ";
}
$ I ++;
}
}
Mysql_close ();
}
?>
Copy the js code to the clipboard.
Code:


Introduce prototye. some js friends say that this library is too large or that they can use jquery if they are not used to it. js framework or directly create ajax objects. I don't want to talk about this anymore. prototye is directly referenced here. js framework

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.