simcoweb Posted December 28, 2007 Share Posted December 28, 2007 I'm creating a directory of nationwide lenders of which can elect to be shown in the Top 3 of the results for their category. I have a field in the 'members' table for top_3 with the value being either 1 for no or 0 for yes, that they are not in/in the top 3. So, what I want to do is in my query for displaying the results of the search is place a priority on those that qualify, show them in the top 3..then the remainder below that. This would be similar to the 'sponsored' links you see in many directories. I just have a snippet of the query as a starter: <?php $sql = "SELECT * FROM amember_members WHERE is_lender='0' AND category='$category' AND loan_type='$loantype' AND loan_amount='$loanamount' ORDER BY top_3"; ?> So, the query should pull all results matching certain criteria (loan amount, loan type, etc.) THEN prioritize the display IF the lender is designated in the top 3. I searched around for something on this but couldn't find anything specific. Quote Link to comment https://forums.phpfreaks.com/topic/83501-need-query-help-to-place-priority-on-display-of-search-results/ Share on other sites More sharing options...
Barand Posted December 28, 2007 Share Posted December 28, 2007 Your query should put the 0s at the top Problem is ? ??? Quote Link to comment https://forums.phpfreaks.com/topic/83501-need-query-help-to-place-priority-on-display-of-search-results/#findComment-424825 Share on other sites More sharing options...
GingerRobot Posted December 28, 2007 Share Posted December 28, 2007 Problem is 1s should be on the top? You need to put them in ascending order: <?php $sql = "SELECT * FROM amember_members WHERE is_lender='0' AND category='$category' AND loan_type='$loantype' AND loan_amount='$loanamount' ORDER BY top_3 ASC"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/83501-need-query-help-to-place-priority-on-display-of-search-results/#findComment-424835 Share on other sites More sharing options...
Barand Posted December 28, 2007 Share Posted December 28, 2007 1 for no or 0 for yes, that they are not in/in the top 3. 0s (yes) need to be at the top. So you are right saying ASC (which is the default anyway) if for the wrong reason, but if you wanted 1s at the top then you would need DESC Quote Link to comment https://forums.phpfreaks.com/topic/83501-need-query-help-to-place-priority-on-display-of-search-results/#findComment-424840 Share on other sites More sharing options...
simcoweb Posted December 28, 2007 Author Share Posted December 28, 2007 First, as always, thanks for the posts! Ok, the 0's should be on top. I guess what I thought would happen is the 0's would display and then nothing else after the 0's ran out. Simple logic running through my simple mind. display 0's 1's don't display cuz they ain't 0's So, if i'm getting the jist of your comments, it will display ALL the results but just prioritize to the 0's then when those run out displays the 1's automatically. Quote Link to comment https://forums.phpfreaks.com/topic/83501-need-query-help-to-place-priority-on-display-of-search-results/#findComment-424860 Share on other sites More sharing options...
Barand Posted December 28, 2007 Share Posted December 28, 2007 So, if i'm getting the jist of your comments, it will display ALL the results but just prioritize to the 0's then when those run out displays the 1's automatically. Have you tried your query yet? Quote Link to comment https://forums.phpfreaks.com/topic/83501-need-query-help-to-place-priority-on-display-of-search-results/#findComment-424867 Share on other sites More sharing options...
GingerRobot Posted December 28, 2007 Share Posted December 28, 2007 If you only want to display results where `top_3` is 0, add that to your search parameters: <?php $sql = "SELECT * FROM amember_members WHERE is_lender='0' AND category='$category' AND loan_type='$loantype' AND loan_amount='$loanamount' AND top_3 = 0"; ?> Or have i misunderstood? Quote Link to comment https://forums.phpfreaks.com/topic/83501-need-query-help-to-place-priority-on-display-of-search-results/#findComment-424869 Share on other sites More sharing options...
Barand Posted December 28, 2007 Share Posted December 28, 2007 Over to you GR (you've got the "chip"). I don't think he even knows if a problem exists or not yet. Certainly no specific problem has been defined. We don't even know if his query gives him what he wants or not. Quote Link to comment https://forums.phpfreaks.com/topic/83501-need-query-help-to-place-priority-on-display-of-search-results/#findComment-424878 Share on other sites More sharing options...
GingerRobot Posted December 28, 2007 Share Posted December 28, 2007 Yeah, i know - i was just trying to avoid another ambiguous question. I seem to have gotten into the habit of trying to guess what the question is - not entirely sure why. Quote Link to comment https://forums.phpfreaks.com/topic/83501-need-query-help-to-place-priority-on-display-of-search-results/#findComment-424883 Share on other sites More sharing options...
simcoweb Posted December 28, 2007 Author Share Posted December 28, 2007 ding! ding! ding! Barand wins the gold monkey! I have NOT tried it...yet! I guess I figured I could 'solve' any issues before banging my head against the wall for an hour or two. I will give 'er a rip and report back Quote Link to comment https://forums.phpfreaks.com/topic/83501-need-query-help-to-place-priority-on-display-of-search-results/#findComment-424887 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.