Hello,
I am using the following code to display a search from MySQL database. My problem is if I try to search database with several keywords, the search doesn't find any results. For example if I search for color and type "red" in my search field it would give me several results, but if I search for color and type red blue, it won't show any resolts whatsoever. How can I make my search to search for several keywords at the same time.
<html>
<head>
<title>Search Results</title>
</head>
<body>
<h1>Search Results</h1>
<?
if (!$searchtype || !$searchterm)
{
echo "You have not entered search details. Please go back and try again.";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
@ $db = mysql_pconnect("localhost", "root", "password"
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}
mysql_select_db("catalog"
$query = "select * from cars where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "<p>Number of records found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<p><strong>".($i+1).". Model: ";
echo stripslashes($row["model"]);
echo "</strong><br>Color: ";
echo stripslashes($row["color"]);
echo "<br>Year: ";
echo stripslashes($row["year"]);
echo "<br>Price: ";
echo stripslashes($row["price"]);
echo "</p>";
}
?>
</body>
</html>
I am using the following code to display a search from MySQL database. My problem is if I try to search database with several keywords, the search doesn't find any results. For example if I search for color and type "red" in my search field it would give me several results, but if I search for color and type red blue, it won't show any resolts whatsoever. How can I make my search to search for several keywords at the same time.
<html>
<head>
<title>Search Results</title>
</head>
<body>
<h1>Search Results</h1>
<?
if (!$searchtype || !$searchterm)
{
echo "You have not entered search details. Please go back and try again.";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
@ $db = mysql_pconnect("localhost", "root", "password"
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}
mysql_select_db("catalog"
$query = "select * from cars where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "<p>Number of records found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<p><strong>".($i+1).". Model: ";
echo stripslashes($row["model"]);
echo "</strong><br>Color: ";
echo stripslashes($row["color"]);
echo "<br>Year: ";
echo stripslashes($row["year"]);
echo "<br>Price: ";
echo stripslashes($row["price"]);
echo "</p>";
}
?>
</body>
</html>