johnrb87 Posted July 11, 2010 Share Posted July 11, 2010 Hello everyone I have the following QUERY SELECT * FROM `places` WHERE `resort` = '.$_GET['q'].' This works great and the values I have stored in the db are; England Turkey USA Brazil So my QUERY could look like SELECT * FROM `places` WHERE `resort` = 'Turkey' or SELECT * FROM `places` WHERE `resort` = 'USA' The problem I have is that some people are spelling names incorrectly and for example, someone spelt Brazil like Brazill and Turkey like Turkie I did think of the option of a spell checker, so something like "Did you mean "Turkey"" but I don't really want to add a spell checker and there is no where in the page design for that to do. Instead I wanted to find out if there is anyway in which SQL can do a partial lookup, so that even if someone spells a word slight wrong or puts a character in the wrong place, then it would still return a result Is there anyway to get PHP or my QUERY to do this? Thanks all John Link to comment https://forums.phpfreaks.com/topic/207411-query-better-results/ Share on other sites More sharing options...
themistral Posted July 12, 2010 Share Posted July 12, 2010 The only thing I could think of would be to query the database for the full string, if that doesn't return any results then take off the last letter and query, if that doesn't return anything then take off another letter etc. So $q = 'Turkie'; "SELECT * FROM `places` WHERE `resort` = '.$_GET['q'].'" // get the string length of $q $qlength = strlen($q); // take off the last letter of $q $q = substr($q, 0, ($qlength)-1); // This would return 'Turki'; "SELECT * FROM `places` WHERE `resort` = '.$q.'%" // the percentage sign is a wildcard $qlength = strlen($q); // take off the last letter of $q $q = substr($q, 0, ($qlength)-1); // This would return 'Turk'; "SELECT * FROM `places` WHERE `resort` = '.$q.'%" This would then return anything matching 'Turk.....' I'm not sure this would be very efficient though so it may be better to manipulate the search string before putting it through the database. Link to comment https://forums.phpfreaks.com/topic/207411-query-better-results/#findComment-1084774 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.