okay im writing a listing website and the search need to list all listing where the Town is LIKE the town specified by the user here is my code:
<?php
include "../config.php";
$town = $_POST['town'];
$name = $_POST['name'];
$county = $_POST['county'];
$street = $_POST['street'];
$type = $_POST['type'];
$phpself = $_SERVER['PHP_SELF'];
if(empty($town) && empty($name) && empty($county) && empty($street) && empty($type))
{
echo "<form method=\"POST\" action=\"$url\">
Town: <br>
<input type=\"text\" name=\"town\">
<br>
Name: <br>
<input type=\"text\" name=\"name\">
<br>
County: <br>
<input type=\"text\" name=\"county\">
<br>
Street: <br>
<input type=\"text\" name=\"street\">
<br>
Type: <br>
<input type=\"text\" name=\"type\">
<br>
<input Type=\"submit\" value=\"Seach\">";
}else{
if(empty($name) && empty($county) && empty($street) && empty($type))
{
//search by town
$searchst = "SELECT * FROM listings WHERE Town LIKE '$town'";
}
elseif(empty($town) && empty($county) && empty($street) && empty($type))
{
//search by name
$searchst = "SELECT * FROM listings WHERE Name LIKE '$name'";
}
elseif(empty($town) && empty($name) && empty($street) && empty($type))
{
//search by county
$searchst = "SELECT * FROM listings WHERE County LIKE '$county'";
}
elseif(empty($town) && empty($name) && empty($county) && empty($type))
{
//search by street
$searchst = "SELECT * FROM listings WHERE Street LIKE '$street'";
}
elseif(empty($town) && empty($name) && empty($county) && empty($street))
{
//search by type
$searchst = "SELECT * FROM listings WHERE Type LIKE '$type'";
}
echo $searchst;
$search = mysql_query($searchst)or die(mysql_error());
while ($row = mysql_fetch_array($search)){
$name = $row['Name'];
$street = $row['Street'];
$town = $row['Town'];
$county = $row['County'];
$postcode = $row['Postcode'];
$phone = $row['Phone'];
echo "<table border=\"1\">";
echo "<tr><td>Name</td><td>Street</td><td>Town</td><td>County</td><td>Postcode</td><td>Phone Number</td></tr>";
echo "<tr><td>$name</td><td>$street</td><td>$town</td><td>$county</td><td>$postcode</td><td>$phone</td></tr>";
echo "</table>";}}
?>
there are 2 rows in the database:
row 1 town = Lindley
row 2 town = Lindley
ashuming the user mispels Lindley - Lindly how can i get MYSQL to return all results that are similair but with some letters wrong?