我是Mysql Php的初学者。我想创建一个搜索框,它可以查找包含在mysql中搜索多个表的单词的行。我有一个脚本通过互联网,这是给出下面。当我键入多个单词时,它会显示具有最小搜索词的行。但我希望它只会显示搜索多个单词的行。请帮帮我。在Mysql中一次搜索多个单词php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
<head>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=UTF-8'/>
<title>Page title</title>
<style type="text/css">
table {
border-collapse: collapse;
border: solid 1px black;
}
td {
padding: 2px 6px;
border: solid 1px black;
}
</style>
</head>
<body>
<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
<p>Search for: <input type='text' name='search' size='20'
maxlength='64'></p>
<p><input type='submit' value='Search'></p>
</form>
<?php
if(isset($_POST['search']))
{
$connx = mysql_connect('localhost', '*****', '*****') or
die("connx");
$db = mysql_select_db('test') or die(mysql_error());
# convert to upper case, trim it, and replace spaces with "|":
$search = (ini_get('magic_quotes_gpc')) ?
stripslashes($_POST['search']) :
$_POST['search'];
$search = mysql_real_escape_string($search);
$search = strtoupper(preg_replace('/\s+/', '|',
trim($_POST['search'])));
# create a MySQL REGEXP for the search:
$regexp = "REGEXP '[[:<:]]($search)[[:>:]]'";
$query = "SELECT * FROM `users` WHERE UPPER(`description`) $regexp
OR ".
"`name` $regexp";
$result = mysql_query($query) or die($query . " - " .
mysql_error());
echo "<table>\n";
while($row = mysql_fetch_assoc($result))
{
echo "<tr>";
foreach($row as $key => $value)
{
echo "<td>$value</td>";
}
echo "</tr>\n";
}
}
?>
</body>
</html>
只是一个旁注,'mysql_' [将会过时](http://news.php.net/php.internals/53799)。替代品是'mysqli'和'PDO' – codingbiz