Numerical sequesnce problem

Discussion in 'PHP' started by jc@ukzone.com, Mar 11, 2008.

  1. #1
    I have a message board that runs in php/mysql. It lists the messages in numerical sequence in decending order:
    $qry .= " ORDER BY reference DESC" ;

    This has worked fine until now.
    The numbers got up to 9999 and then the next number is 10000 was displayed at the bottom or the list.
    Numbers are generated from a text file, which increments OK (it is now on 10013).

    Does anybody know why this has happened and is there a cure for it.

    Thanks

    John C
     
    jc@ukzone.com, Mar 11, 2008 IP
  2. CreativeClans

    CreativeClans Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Is reference defined as numeric or as text?
    It should be numeric, otherwise ordering won't give you the desired result. Unless you change all numbers smaller than '10000' in '09999', '09998', etc (notice the leading zero).

    By the way, if you're using an incrementing order number, why don't you use the MYSQL AUTOINCREMENT feature?
     
    CreativeClans, Mar 11, 2008 IP
  3. jc@ukzone.com

    jc@ukzone.com Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi CreativeClans (Grunt)

    Thanks for your response.
    I didn't think about the type. I had it set to VARCHAR and changed it to INT and it now works fine.

    The idea of using the auto increment function appeals to me.
    I used a text file when the board was run in perl so I just continued with it.

    If I use the auto increment, how would I start it to continue from where it is now? Do I just change the field to auto_increment and set the default to the present number?

    You help is very much appreciated.

    John C
     
    jc@ukzone.com, Mar 11, 2008 IP
  4. CreativeClans

    CreativeClans Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hmm, don't know about that. Sorry. Maybe someone else?
     
    CreativeClans, Mar 11, 2008 IP