1internet Posted January 20, 2013 Share Posted January 20, 2013 I am trying to create a search form with one field that will search through one table, but through all the columns. I just can't seem to work it out. Also is there some way to prioritize the results, e.g. if the keyword is in the title then rank it above the results that have the keyword in the description? Quote Link to comment https://forums.phpfreaks.com/topic/273403-searching-across-multiple-columns/ Share on other sites More sharing options...
stijn0713 Posted January 20, 2013 Share Posted January 20, 2013 (edited) I just can't seem to work it out. then you might want to take a better look at the select query http://dev.mysql.com.../en/select.html and especially the WHERE statement Also is there some way to prioritize the results, e.g. if the keyword is in the title then rank it above the results that have the keyword in the description? there is, obviously Edited January 20, 2013 by stijn0713 Quote Link to comment https://forums.phpfreaks.com/topic/273403-searching-across-multiple-columns/#findComment-1407131 Share on other sites More sharing options...
1internet Posted January 20, 2013 Author Share Posted January 20, 2013 I understand WHERE statments, but I just don't know what the query would be if I wanted to search multiple fields. WHERE `firstName` LIKE '%".$searchFirstName."%, but what if I wanted to search other fields, and how do I priortize one over the other, without duplicate entries? Quote Link to comment https://forums.phpfreaks.com/topic/273403-searching-across-multiple-columns/#findComment-1407139 Share on other sites More sharing options...
stijn0713 Posted January 20, 2013 Share Posted January 20, 2013 e.g. : $sql = "SELECT * FROM test WHERE car LIKE '%$search%' OR colour LIKE '%$search%' ORDER BY case when car LIKE '%$search%' then 1 when colour LIKE '%$search%' then 2 end"; Quote Link to comment https://forums.phpfreaks.com/topic/273403-searching-across-multiple-columns/#findComment-1407144 Share on other sites More sharing options...
stijn0713 Posted January 20, 2013 Share Posted January 20, 2013 forgot: if you want only distinc values, you need to add group by car, colour before order by Quote Link to comment https://forums.phpfreaks.com/topic/273403-searching-across-multiple-columns/#findComment-1407158 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.