Jump to content

Need query help to place priority on display of search results


Recommended Posts

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.

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";
?>

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

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.

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?

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?

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.

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 :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.