how can i make sn number start from 1 when the new year is start.

Discussion in 'PHP' started by khs555, Nov 26, 2006.

  1. #1
    Hi evryone ,
    I'm working in a program for storing inbox and outbox documentsand
    and in mysql the sn number is the primary key.
    the number must be as 01/2006 the next nuber will be 02/2006
    my problem is how can i make this sequance number start from 1 when the year will come 2007 and the first number will be 01/2007 and also for the next years>>

    Any help regarding this will be highly appreciated.
     
    khs555, Nov 26, 2006 IP
  2. Nikolas

    Nikolas Well-Known Member

    Messages:
    1,022
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    150
    #2
    I am not sure what you are saying, but I guess this is what you want :

    
    date( 'm/Y', time())
    
    PHP:
     
    Nikolas, Nov 26, 2006 IP
  3. khs555

    khs555 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thank you Nikolas
    but not that wat i want.
    for exampe the following number>
    112/2006
    122 is the nember of the document no the month and it will be auto_increment
    2006 is the year
    and i want the number of document starting from 1 when the uear be come 2007 >>>> and agein it will start from 1 when the new year come
     
    khs555, Nov 26, 2006 IP
  4. Nikolas

    Nikolas Well-Known Member

    Messages:
    1,022
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    150
    #4
    Let's say that you keep the higher id in a variable called $max, and the maximum recorder year (eg. 2006) in a variable called $mYear.

    Then :
    
    $newID = (date('Y') == $mYear ? $max++: 1);
    
    PHP:
     
    Nikolas, Nov 26, 2006 IP