Jump to content

How to only get "partial" results returned in a search


CountryGirl

Recommended Posts

The code I'm using for my search is:

 

WHERE Asmnt_Parcel.OwnersName LIKE '{$search}'

 

Now, this works for two of the searches I've built. But, I'm needing the results to return a bit differently on this search page. I can't just type in someone's last name, like "Bennett" and have all "Bennett"s show up in the results. It'll only return exact results (which is good for the other two searches), so someone has to enter the full name as it is in the database, like "Bennett, John P."

 

What would be the best way to let people do more "general" searches?

 

This is the rest of my coding incase it'll help answer my question any :) ~

 

$search = $_POST['search'];

if ($search) // perform search only if a string was entered.
{
   $con = mysql_connect($dbHost, $dbUser, $dbPass) or die("Failed to connect to MySQL Server. Error: " . mysql_error());
   mysql_select_db($dbDatabase) or die("Failed to connect to database {$dbDatabase}. Error: " . mysql_error());
   
   
   $query = "SELECT Appr_Value.ApprID as id, Appr_Value.Account, Asmnt_Parcel.OwnersName, Asmnt_Situs.Situs
           FROM Appr_Value
           INNER JOIN Asmnt_Parcel
           ON Appr_Value.Account=Asmnt_Parcel.Account
           INNER JOIN Asmnt_Situs
           ON Appr_Value.Account=Asmnt_Situs.Account
           WHERE Asmnt_Parcel.OwnersName LIKE '{$search}'
             ORDER BY Appr_Value.Account ASC";
   $result = mysql_query($query, $con) or die(mysql_error().": $query");

   if ($result)
   {
      echo "Results:<br><br>";
      echo "<table width=90% align=center border=1><tr>
      <td align=center bgcolor=#4A6B3F>Account</td>
      <td align=center bgcolor=#4A6B3F>Owners Name</td>
      <td align=center bgcolor=#4A6B3F>Situs</td>
      </tr>";
   
      while ($r = mysql_fetch_array($result))
      { // Begin while
         $act = $r["Account"]; 
         $name = $r["OwnersName"];
         $situs = $r["Situs"];
         echo "<tr>
            <td><a href='formresults.php?id=".$r['id']."'>$act</td>
            <td>$name</td>
            <td>$situs</td>
            </tr>";
      } // end while
      
      echo "</table>";
   }
   else
   {
      echo "Sorry, please try your search again.";
   }
}
else
{
   echo "";
}
?>

 

Thanks for any tips, advice & help!

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.