yami007 Posted December 31, 2011 Share Posted December 31, 2011 i want to sort the available words by the "searched word"...is there any way ? <?php $query = "SELECT * FROM ce_cour_chap WHERE nom LIKE'%$find%' ORDER BY nom"; $result = mysql_query($query); while($search = mysql_fetch_array( $result )) { echo $search['nom']." - ".$search["chid"]."<br/>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/254143-search-sql-order-by-priority-of-the-searched-term/ Share on other sites More sharing options...
QuickOldCar Posted December 31, 2011 Share Posted December 31, 2011 There is many types of sorting. Please explain in what way, or in how of the sorting you desire. Quote Link to comment https://forums.phpfreaks.com/topic/254143-search-sql-order-by-priority-of-the-searched-term/#findComment-1302922 Share on other sites More sharing options...
yami007 Posted December 31, 2011 Author Share Posted December 31, 2011 Thanks for your time ! Let's assume a user typed "plan" Regardless of the database's fields, I want to sort them by the word given "plan". if "plan" is the first word of a sentence, it should go first even if another entry start with an a for example: "plan" should go first before "a plan" - plan - planning - a plan - the planning Quote Link to comment https://forums.phpfreaks.com/topic/254143-search-sql-order-by-priority-of-the-searched-term/#findComment-1302923 Share on other sites More sharing options...
kicken Posted December 31, 2011 Share Posted December 31, 2011 Probably the best you could do with your query is using something like: ORDER BY INSTR(nom, 'plan') Quote Link to comment https://forums.phpfreaks.com/topic/254143-search-sql-order-by-priority-of-the-searched-term/#findComment-1302924 Share on other sites More sharing options...
yami007 Posted December 31, 2011 Author Share Posted December 31, 2011 Probably the best you could do with your query is using something like: ORDER BY INSTR(nom, 'plan') Thank you kicken, that's what I want Quote Link to comment https://forums.phpfreaks.com/topic/254143-search-sql-order-by-priority-of-the-searched-term/#findComment-1302925 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.