LinuxÒÁµéÔ°ÂÛ̳'s Archiver

allen.yyd ·¢±íÓÚ 2006-4-13 20:10

ÇóÖú£ºÓйØPHPµ÷ÓÃMYSQL×ö²éѯ

ÎÒµÄÊý¾Ý¿âbooksµÄÓû§Ãû£ºbookorama£¬ÃÜÂ룺bookorama123
ÔÚLINUX Ï£¬²éѯһÇÐÕý³£
ÎÒÓиöPHPÒ³ÃæÓÃÀ´×ö²éѯ£¬µ«ÊÇÒ»Ö±ÏÔʾ¿Õ°×£¬Çë°ïÎÒ¿´¿´´úÂëʲôµØ·½ÓÐÎÊÌâ
»¹ÊÇÎÒÊý¾Ý¿â½¨Á¢ÓÐÎÊÌ⣻



<html>
<head>
  <title>Book-O-Rama Search Results</title>
</head>
<body>
<h1>Book-O-Rama Search Results</h1>
<?php
  // create short variable names
  $searchtype=$_POST['searchtype'];
  $searchterm=$_POST['searchterm'];

  $searchterm= trim($searchterm);

  if (!$searchtype || !$searchterm)
  {
     echo 'You have not entered search details.  Please go back and try again.';
     exit;
  }
  
  if (!get_magic_quotes_gpc())
  {
    $searchtype = addslashes($searchtype);
    $searchterm = addslashes($searchterm);
  }

  @ $db = new mysqli('localhost', 'bookorama', 'bookorama123', 'books');

  if (mysqli_connect_errno())
  {
     echo 'Error: Could not connect to database.  Please try again later.';
     exit;
  }

  $query = "select * from books where ".$searchtype." like '%".$searchterm."%'";
  $result = $db->query($query);

  $num_results = $result->num_rows;

  echo '<p>Number of books found: '.$num_results.'</p>';

  for ($i=0; $i <$num_results; $i++)
  {
     $row = $result->fetch_assoc();
     echo '<p><strong>'.($i+1).'. Title: ';
     echo htmlspecialchars(stripslashes($row['title']));
     echo '</strong><br />Author: ';
     echo stripslashes($row['author']);
     echo '<br />ISBN: ';
     echo stripslashes($row['isbn']);
     echo '<br />Price: ';
     echo stripslashes($row['price']);
     echo '</p>';
  }
  
  $result->free();
  $db->close();

?>
</body>
</html>

Ò³: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.