PHP Simple content Query code using SQL like fuzzy query

Source: Internet
Author: User
Tags mysql tutorial

<meta http-equiv= "Content-type" content= "text/html; charset=gb2312"/>
<script language= "JavaScript Tutorial"
 check111cnnet ()
 {
  var keyword = myfm.keyword.value;
  if (keyword = = ")
  {
   alert (' www.111cn.net prompts you: Please enter the content to query ');
   return false;
  }
 }
</script>

<body>
<form id= "myFM" name= "myFM" method= "POST" action= "" >
<label>
Enter Query keywords:
<input type= "text" name= "keyword"/>
</label>
<label>
<input type= "Submit" name= "Submit" value= "submitted" onclick= "return Check111cnnet ();"/>
</label>
</form>
</body>
<?php
Create a Database Tutorial connection
MySQL tutorial _connect (' localhost ', ' 111cn.net ', ' www.111cn.net ');
mysql_select_db (' www.111cn.net ');//Database selection
mysql_query (' Set names "GBK");

Progress Query Operations

if ($_post)
{
  $keyword = $_post[' keyword '];
  $sql = "SELECT * from search where title is like '% $key word% ' Limit 0,10 ';
  $query = mysql_query ($sql) or Die ("www.111cn.net prompts you: query is wrong");
 
 if (mysql_num_rows ($query))
 {
  while ($rs = mysql_fetch_array ($query)
  {
   echo $rs [' title '];
  }
 
 else  &NBSP
 {
  echo ' no content to look for ';
 
}

/*
Data table structure
CREATE TABLE ' 111cnNet '. ' Test ' (
' ID ' INT (8) not NULL auto_increment,
' Title ' CHAR ($) NULL,
' Content ' TEXT NULL,
PRIMARY KEY (' id ')
) ENGINE
*/
function parsing
Mysql_connect//database connection has three parameters for the database server name, username, password
There are two mysql_select_db//parameters, the second is optional, the first database name, and the second database connection $connwww.111cn.net
mysql_query (' Set names "GBK"); This sentence is more important, is to set the reading of the database content encoding, this sentence to be set up with the document editing consistent, otherwise may appear garbled.

mysql_query//Data query, there are two parameters, the first must, for SQL query statement.
Mysql_num_rows//Statistics mysql_query query record how many bars, return to int type
Mysql_fetch_array//Read the current Recordset one record to save to the array.
$_post
If Else
While
Original site reprint must indicate the source or the source of responsibility http://www.111cn.net/phper/php.html
?>

Related Article

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.