Sorting Results on basis of Average Ratings

Discussion in 'PHP' started by Im The ONE, Feb 11, 2008.

  1. #1
    I have site http://gamblejam.com/bookmakers.php (I didn't post for promoting)
    Presently they are sorted in default order but I'd like them to be show in such order that site with high rating in both bonus and site fields should be first and so on. bonusrating and siterating in db store values for them. Is it possible to take out average of bonus+siterating then sort them in DESC order?
    I have attached a screenshot of my DB for referrence.
    I'll appreciate any sort of help. Thanks
     

    Attached Files:

    • db.JPG
      db.JPG
      File size:
      9.3 KB
      Views:
      63
    Im The ONE, Feb 11, 2008 IP
  2. jnestor

    jnestor Peon

    Messages:
    133
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It would be if bonus and siterating were numerical fields instead of text strings.
     
    jnestor, Feb 11, 2008 IP
  3. Im The ONE

    Im The ONE Peon

    Messages:
    800
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Does that makes any difference? I mean "ORDER by siterating DESC" always worked for me
     
    Im The ONE, Feb 11, 2008 IP
  4. jnestor

    jnestor Peon

    Messages:
    133
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Of course it makes a difference.

    Put these in order:
    B, C, A

    Now tell me what's (B + C) / 2

    Btw, I don't think you want to average those fields anyway. You said you want the site with high ratings in both. Averaging those won't get you that.

    What you need to do is figure out which field is more important and sort by that one first and the other second. Let's say siterating is more important. You'd do

    ORDER BY siterating DESC, bonus DESC

    So it would sort by siterating and for rows with equal siterating you'd sort those by bonus.

    If you really want to sort by which row has the highest combined siterating + bonus you'll either need to convert those fields to a numerical type or add a third column where you store the combined value.
     
    jnestor, Feb 11, 2008 IP
    Im The ONE likes this.
  5. Im The ONE

    Im The ONE Peon

    Messages:
    800
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you very much, I got desired results. The problem was that I was trying it as "siterating,bonus DESC" while it should have been like what you mentioned. Thanks again
     
    Im The ONE, Feb 11, 2008 IP