cryp7 Posted July 31, 2007 Share Posted July 31, 2007 Hello, I have searched all over the internet for a solution and have not found what i was looking for so i thought I'd see if you lovely people would be able to help... I'm looking for a script that filters, multiple times, from my MySQl database and the selects exact match results or results closest to the input data. The only way i could think of doing it is like: $query = mysql_query("SELECT * FROM data WHERE height = '$height' AND WHERE weight LIKE '$weight' AND WHERE shoe LIKE '$shoe' AND WHERE useage LIKE '$useage' AND WHERE skill LIKE '$skill'") or die(mysql_error()); This doesn't work and gives this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE weight LIKE '14' AND WHERE shoe LIKE '3' AND WHERE useage LIKE 'touring' A' at line 1 I'm really not sure what to try so any help would be appreciated, thanks a lot Andy Quote Link to comment https://forums.phpfreaks.com/topic/62626-mulitiple-filters-in-select/ Share on other sites More sharing options...
hostfreak Posted July 31, 2007 Share Posted July 31, 2007 No need for the WHERE clause that many times: $query = mysql_query("SELECT * FROM data WHERE height = '$height' AND weight LIKE '$weight' AND shoe LIKE '$shoe' AND useage LIKE '$useage' AND skill LIKE '$skill'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/62626-mulitiple-filters-in-select/#findComment-311753 Share on other sites More sharing options...
cryp7 Posted July 31, 2007 Author Share Posted July 31, 2007 Ah excellent, much simpler than i expected thanks. Now one more thing that would be a great help to know is... the code above only shows results if there is an exact match is there an way of printing the results that a close matches and then ordering them in order of closest... I have search the net for this and couldn't find anything. Thanks in advanced Andy Quote Link to comment https://forums.phpfreaks.com/topic/62626-mulitiple-filters-in-select/#findComment-312283 Share on other sites More sharing options...
hostfreak Posted July 31, 2007 Share Posted July 31, 2007 Sure $query = mysql_query("SELECT * FROM data WHERE height = '%$height%' AND weight LIKE '%$weight%' AND shoe LIKE '%$shoe%' AND useage LIKE '%$useage%' AND skill LIKE '%$skill%'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/62626-mulitiple-filters-in-select/#findComment-312285 Share on other sites More sharing options...
almightyegg Posted July 31, 2007 Share Posted July 31, 2007 can I just ask what exactly does the % do in that? Just for future reference Quote Link to comment https://forums.phpfreaks.com/topic/62626-mulitiple-filters-in-select/#findComment-312291 Share on other sites More sharing options...
Psycho Posted July 31, 2007 Share Posted July 31, 2007 Hmmm.. I don't think the LIKE parameter is what you are looking for. It allows you to search for a value that is included in the database, but the database value can include more data. It does not search for similar value - at lest not how I interpret similar. The % tells the query that additional data may come before or after the search string: LIKE '%car' = 'car' LIKE '%car' = 'race car' LIKE '%car' != 'carpet' LIKE 'car%' = 'carpet' LIKE 'car%' != 'blue carpet' LIKE '%car%' = 'blue carpet' Quote Link to comment https://forums.phpfreaks.com/topic/62626-mulitiple-filters-in-select/#findComment-312296 Share on other sites More sharing options...
almightyegg Posted July 31, 2007 Share Posted July 31, 2007 nifty! I'll be needing that myself thanks Quote Link to comment https://forums.phpfreaks.com/topic/62626-mulitiple-filters-in-select/#findComment-312299 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.