1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

ordering by number

Discussion in 'PHP' started by e10, Apr 6, 2010.

  1. #1
    I am trying to get listings to sort in ascending order according to a number field but the results are shown in a wacky order like 103, 113, 17, 202 ...

    This is what I used:


    $result = mysql_query("SELECT * From name-of-table where xxxx='parameter1'and xxxx='parameter2' ORDER BY name-of-field");

    Would someone be kind enough to set me straight here please?:confused:
     
    e10, Apr 6, 2010 IP
  2. flakas123

    flakas123 Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ORDER BY name-of-field ASC
     
    flakas123, Apr 6, 2010 IP
  3. e10

    e10 Well-Known Member

    Messages:
    2,250
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    185
    #3
    flakas123, I appreciate you trying to help but that doesn't solve my problem. It is not that the order is going in the wrong direction but that the order is not running sequentially.

    Now, using the ASC it runs 17, 202, 22, 24, 24, 24, 25, 32...

    It should be 17, 22, 24, 24, 24, 25 ...

    Any more ideas?
     
    e10, Apr 6, 2010 IP
  4. e10

    e10 Well-Known Member

    Messages:
    2,250
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    185
    #4
    e10, Apr 6, 2010 IP
  5. ThomasTwen

    ThomasTwen Peon

    Messages:
    113
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The piece you posted is absolutely correct. You might be doing something wrong when you replace the placeholders with the actual values - we need to see the actual code in order to help you.
     
    ThomasTwen, Apr 6, 2010 IP
  6. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #6
    Thank you for sharing that link.

    You said on your first post "a number field" and the comment on that page from the MySQL 5.0 docs shows us how to order strings as numbers. So I assume you are using a string field (maybe a varchar) for storing numbers.

    Am I right?

    Cheers
     
    nabil_kadimi, Apr 6, 2010 IP
    e10 likes this.
  7. e10

    e10 Well-Known Member

    Messages:
    2,250
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    185
    #7
    Yes, you are correct, Nabil. And as you may have guessed I am not the sharpest tool in the shed when it comes to things related to dbases. :)
     
    e10, Apr 6, 2010 IP
    nabil_kadimi likes this.