Project structure:
498) this.width=498; ' OnMouseWheel = ' javascript:return big (This) ' height= "183" alt= "\" width= "274" src= "/HTTP/ Www.bkjia.com/uploadfile/2013/0904/20130904095406958.png "/>
Start Search: Search for keywords here ("big" "This")
498) this.width=498; ' OnMouseWheel = ' javascript:return big (This) ' height= "269" alt= "\" width= "640" src= "/HTTP/ Www.bkjia.com/uploadfile/2013/0904/20130904095406563.png "/>
Search results: Highlighting
498) this.width=498; ' OnMouseWheel = ' javascript:return big (This) ' height= "480" alt= "\" width= "565" src= "/HTTP/ Www.bkjia.com/uploadfile/2013/0904/20130904095406399.png "/>
Database structure required for the project:
498) this.width=498; ' OnMouseWheel = ' javascript:return big (This) ' height= "187" alt= "\" width= "640" src= "/HTTP/ Www.bkjia.com/uploadfile/2013/0904/20130904095406831.png "/>
Implementation code:
conn.php
-
- $conn = @ mysql_connect ("localhost""root " "" or die("Database link Error");
- mysql_select_db ("form"$conn);
- mysql_query ("set names ' GBK '");
searchanddisplaywithcolor.php
-
- include ' conn.php ';
- ?>
- "Center" >
-
-
- "0"align="Center"cellpadding="5"
- cellspacing= "1" bgcolor= "#add3ef" >
-
- //keyword is not empty when performing a related search
- if ($_get[' KeyWord ']) {
- //Use space to split the keyword
- $key = Explode (', $_get[KeyWord]);
- $sql = "SELECT * from message where the title like ' $key [0] ' or title like ' $key [1] ' or content like ' $key [0] ' or content like ' % $key [1]% '];
- $query =mysql_query ($sql);
- while ($row=mysql_fetch_array ($query)) {
- //Replace keywords and highlight keywords
- $row [Title]=preg_replace ("/$key [0]/i", "$key [0]", $row [title]);
- $row [Title]=preg_replace ("/$key [0]/i", "$key [1]", $row [title]);
- $row [Content]=preg_replace ("/$key [0]/i", "$key [0]", $row[content]);
- $row [Content]=preg_replace ("/$key [1]/i", "$key [1]", $row[content]);
- ?>
-
-
"#eff3ff">
-
-
-
"#ffffff">
-
-
-
"#ffffff">
-
-
-
- }
- ?>
Title:"Black"> $row[title]?> User:"BLACK"> $row [User]?>- "Right" >"preedit.php?id= "> Edit |
- href= "delete.php?id= "> Delete
|
| Content: $row[content]?> |
- "Right" > Published date: $row [lastdate]?>
|
Note: In this small program, a little bit of a disadvantage is that only two keywords can be searched at the same time, and the middle with a space "" separated, if you just search a keyword, such as: "Big"
The display will appear garbled ... ^|_|^, this is due to the result of the following code:
- $key = Explode ('$_get
If we want to improve, we should make a judgment in the back of this place.
http://www.bkjia.com/PHPjc/445701.html www.bkjia.com true http://www.bkjia.com/PHPjc/445701.html techarticle Project structure: 498) this.width=498; ' OnMouseWheel = ' javascript:return big (This) ' height= "183" alt= "\" width= "274" src= "http ://www.bkjia.com/uploadfile/2013/0904/2013090409540695 ...