PHP/Mysql ROUND function help

Discussion in 'PHP' started by Funk-woo10, Jun 30, 2008.

  1. #1
    Hi all,

    I need some help !

    I need to pull 6 records out of a table with the highest numbers first in desc order.

    Easy...however these numbers are stored like 7.886 or 8.9987 - What i need is to round them down or up in the SELECT query !

    How would i do that ?

    SELECT * from numbertable ORDER BY NUMBERTABLE DESC ***WHERE DO I ROUND THE NUMBER ???**

    Thanks.
     
    Funk-woo10, Jun 30, 2008 IP
  2. ahmadfarhan

    ahmadfarhan Peon

    Messages:
    211
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ahmadfarhan, Jun 30, 2008 IP
  3. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #3
    how would i right that into the query ?
     
    Funk-woo10, Jun 30, 2008 IP
  4. ahmadfarhan

    ahmadfarhan Peon

    Messages:
    211
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    SELECT round(COLUM_NAME_HERE) from numbertable ORDER BY COLUMN_NAME_HERE DESC

    seriously dude.. show some initiative..
     
    ahmadfarhan, Jun 30, 2008 IP
  5. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #5
    haha i was aking for help...not a flamming...thanks anyway.
     
    Funk-woo10, Jun 30, 2008 IP
  6. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #6
    hmm still cant get it to work
     
    Funk-woo10, Jun 30, 2008 IP
  7. ahmadfarhan

    ahmadfarhan Peon

    Messages:
    211
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    what output is it that you want? waht output ou get instead?
    are you sure it's a query error and not a script error?
    rn the query inside mysql and see what's the output...

    a more descriptive account of the problem will help more rather that just "it doesn't work"
     
    ahmadfarhan, Jun 30, 2008 IP
  8. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #8
    
    
    SELECT * FROM rate_members LEFT JOIN pictures ON members.m_id=pictures.i_user WHERE i_status=2 AND i_rating > 2 AND m_type = 1 ORDER BY i_rating DESC Limit 6
    
    PHP:
    lets say i echo $i_rating it would look like this - 7.87585

    What i need is say 7.8 i.e two decimal places !

    Where can i put the ROUND function in the SELECT query ?
     
    Funk-woo10, Jun 30, 2008 IP
  9. ahmadfarhan

    ahmadfarhan Peon

    Messages:
    211
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #9
    don't use *
    you have to list out all the columns that you want to list out.
    for the i_rating column

     select ..... ,round(i_rating,2) from rate_members .........
    Code (markup):
     
    ahmadfarhan, Jun 30, 2008 IP
  10. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #10
    hmm ok, done that now its not even displaying the figure when i echo it.
     
    Funk-woo10, Jun 30, 2008 IP