SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Hybrid View

  1. #1
    SitePoint Zealot Junk's Avatar
    Join Date
    Dec 2004
    Location
    Asia
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink Implementation of reference number - need suggestions

    Hi,


    Currently I am dealing with a sys that track manuscripts. For every manuscript submitted, an auto increment id will assigned. If manuscript is accepted to be published, a reference number will be given.

    The reference number for each accepted script needs to be distinct, logical and must be flexible and allow for future changes.

    I need some suggestions on the implementation of the reference number.

    If you have piror experience, please share with me how you think the reference number should be, such that it will be unique, logical, easy to handle and flexible.

    Thank you so much!

    Have a happy new year!
    Regards,
    Junk

    I am never more keen to learn...

  2. #2
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Junk
    distinct, logical and must be flexible and allow for future changes.
    I'm guessing the ref no. will be stored inta database. Set the ref_no column to unique. That should take care of a few things.

    As for generating the ref no., you can add some logical stuff like first letter of username or first, last name to the start of the string [might help you for searching later on] and then add a random set of letters and/or integers at the other end.

    The 'unique' column in the db should take care of the not duplicating references for future changes in case some collision occurs.

    Of course, this is quite a loose way of doing things. I'm sure there are other better ways. I just cant think right now, just woke up.

    -asT.

  3. #3
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    personally, I use timestamp = time() for that kind of thing.

  4. #4
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    he wants something logical, so i think that kinda rules out timestamp, though i do agree that timestamp would be a very nice way to handle it.

  5. #5
    SitePoint Addict trogdor1024's Avatar
    Join Date
    Oct 2004
    Location
    New Jersey
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I usually combine the date/time into it, but not rely solely on it. Depending how crazy you want to go you may decide to do something like...

    20041231-01-549222

    ... which is

    <year><month><day>-<control number>-<random>

    This is logical, useful, and easily parsable if you need certain info from it. You might populate the control number with a status code or customer sensitivity code (i.e. control numbers of "03" are VIP high priority). The random 6-digits reduce the risk of multilple ref numbers.

    To generate the reference number you might have something like this...
    PHP Code:
    <?
    $seg1 
    date("Ymd");
    $seg2 $controlNum;
    $seg3 rand(100000,999999);

    $refNum $seg1 '-' $seg2 '-' $seg3;
    ?>

  6. #6
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did something along this line once. I was basically tracking orders online.
    I used the format DP04001. DP being an abbreviation of the business name, 04 being the year the order was placed and 001 being the order number for that year.

    Really it just comes down to what sort of information you want to be able to identify from looking at the reference number. If you have user IDs for users able to submit manuscripts that would be a logical inclusion, the date (or part of it) may be relevant, or the person who approves the manuscript might also make an appearance.

    Really only you can decide what information you want contained, and if you want to ensure uniqueness you could incorporate the initial auto increment ID from when the manuscript was submitted into the new reference number when it is approved.

  7. #7
    SitePoint Zealot Junk's Avatar
    Join Date
    Dec 2004
    Location
    Asia
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so so so much for all your very precious and experienced advises!

    I really appreciate your help!

    Have a great year!
    Regards,
    Junk

    I am never more keen to learn...

  8. #8
    SitePoint Zealot Junk's Avatar
    Join Date
    Dec 2004
    Location
    Asia
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    one query.

    How do I count the the number of manuscripts(in the database) already with reference number(accepted scripts) and then add one to this number.

    $sql_max = "SELECT COUNT(*) FROM MANUSCRIPT_TABLE where ref_no != '' ";

    $result = mysql_query($sql_max) or die("SELECT Error: ".mysql_error());

    How do I get the count number? Thanks
    Regards,
    Junk

    I am never more keen to learn...

  9. #9
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Given that you are returning only 1 column and 1 row, try this (untested) code snippet - assuming you SQL query is correct

    PHP Code:
       $sql_max "SELECT COUNT(*) FROM manuscript_table WHERE ref_no != '' ";
       
       
    $result mysql_query($sql_max) or die("SELECT Error: ".mysql_error());
      
      
    // read the first column on the first row from $result
      
    $manuscript_number mysql_result($result0);
    // add one to it to get the next number
     
    $manuscript_number += 1
    hope this helps

  10. #10
    SitePoint Zealot Junk's Avatar
    Join Date
    Dec 2004
    Location
    Asia
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi swdev,

    Thanks for your advise. It works!

    Have a great day!
    Regards,
    Junk

    I am never more keen to learn...

  11. #11
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your welcome.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •