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