How to see if X is in top 5 results (mysql query)

Discussion in 'PHP' started by bobby9101, Oct 18, 2007.

  1. #1
    Hi, I am assigning the numbers 1.00-10 (including decimals) to rows in my table, however when I want to add a new row, I want to see if it's number is in the top 5 results:

    I hope this makes some sense
     
    bobby9101, Oct 18, 2007 IP
  2. theOtherOne

    theOtherOne Well-Known Member

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #2
    I'm not sure, but I guess there's no other method that making a SELECT query with LIMIT 0, 5 at the end, going through that resultset and checking whether one of the results contains your number.

    Would be interested though if somebody knows another method!
     
    theOtherOne, Oct 18, 2007 IP
  3. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you can do it SELECT * from * where *=* LIMIT 5 ASCEND i think that will pretty much do the same though, just take the first 5 numbers you get
     
    Lordy, Oct 18, 2007 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    Get the first 5:

    
    $query = mysql_query("SELECT `count_field` FROM `table_name` ORDER BY `count_field` DESC LIMIT 5");
    
    Code (markup):
    Then you search through:

    
    while($query = mysql_fetch_assoc($query)){
    if($query[0] == $count_field_checking_size){
    echo 'Size Match';
    }
    }
    
    PHP:
     
    Barti1987, Oct 18, 2007 IP
  5. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I found a workaround, thanks though
     
    bobby9101, Oct 18, 2007 IP