CountryGirl Posted April 28, 2010 Share Posted April 28, 2010 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! Link to comment https://forums.phpfreaks.com/topic/200072-how-to-only-get-partial-results-returned-in-a-search/ Share on other sites More sharing options...
Mchl Posted April 28, 2010 Share Posted April 28, 2010 WHERE Asmnt_Parcel.OwnersName LIKE '%$search%' Link to comment https://forums.phpfreaks.com/topic/200072-how-to-only-get-partial-results-returned-in-a-search/#findComment-1050087 Share on other sites More sharing options...
coupe-r Posted April 28, 2010 Share Posted April 28, 2010 You need to use the wildcard % in your query, before or after your $search, depending on how you want to search. Probably before though. Link to comment https://forums.phpfreaks.com/topic/200072-how-to-only-get-partial-results-returned-in-a-search/#findComment-1050088 Share on other sites More sharing options...
CountryGirl Posted May 3, 2010 Author Share Posted May 3, 2010 Thanks guys! I figured it was something like that, just wasn't sure of the exact thing to do . Link to comment https://forums.phpfreaks.com/topic/200072-how-to-only-get-partial-results-returned-in-a-search/#findComment-1052485 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.