SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Order Numbers

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Order Numbers

    I suppose this isn't strictly a PHP question...I am writing the shopping script in PHP, however, so figured I would put it here.

    How do you go about assigning a number to an order? I would like to stay away from just using an auto-increment field.

    What I am thinking is using the customers first and last initial followed by the timestamp. This would (within reason) always be unique, and would actually contain information about the order to boot!

    Is this a bad idea?
    "Do or do not. There is no try." -- Yoda

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    What are your reasons for not wanting to use the auto-increment field?

    Your proposed identifier is redundant; the name and timestamp of the order are already stored.

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    What are your reasons for not wanting to use the auto-increment field?
    I just like having a bit of information stored in the number itself I guess? It's not random but it's damn near guaranteed to be unique....unless two people with the same first and last initials place an order at the exact same second.

    And I just like it. It looks prettier because I know it holds a bit of info I guess. I nitpick far too much, I'm aware of this



    Quote Originally Posted by Dan Grossman View Post
    Your proposed identifier is redundant; the name and timestamp of the order are already stored.
    Can't argue with that.
    "Do or do not. There is no try." -- Yoda

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    do you mean you would like the number to hold some clues so that when you looked at it out of context, on a label or a packing order, you and others have some kind of hint about what it contains?

    How about a reference id like this;

    RF-09-04-0000001

    Where you generate the RF from the users initials, the 09 04 from the date and 1 is the first record.

    You only generate the key when your retrieve the record, use strpad() to pad the final part out to 7 digits.

    The thing is that you still allow the database to hold and manage your id number for you.

    If you aren't sure how to go about generating that type of key from an sql select then ask here.

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    do you mean you would like the number to hold some clues so that when you looked at it out of context, on a label or a packing order, you and others have some kind of hint about what it contains?

    How about a reference id like this;

    RF-09-04-0000001
    Exactly. When viewed in any context, it at least holds the customer initials and the date the order was placed. It...means something. I like that. I even toyed with the idea of adding grand total to it just for good measure.

    Quote Originally Posted by Cups View Post
    If you aren't sure how to go about generating that type of key from an sql select then ask here.
    Generate a reference ID like you said strictly from SQL? If that is what you mean....then no, I have no clue how to do that. Already implemented it in PHP, but would be very interested in learning of a new (and possibly more efficient?) method?

    Thank you guys!
    "Do or do not. There is no try." -- Yoda

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    So you probably have several scenarios where you need to know either a single ref or a list of references, and thinking about it, you might find it easier to just create a new column called reference_no and just save the ref no in that as you create it.

    My comments about an sql select assumed those 3 data are held in a database;

    first letters of name
    date
    id

    Though maybe not all in the same table.

    so look at the following mysql functions:

    date_format

    e.g. select date_format(yourdatefield, '%y-%m') as date_ref..

    concat
    and
    left

    e.g. select concat( left(first_name, 1) , '-', left(last_name, 1) ) as initials_ref ....
    Last edited by Cups; Apr 17, 2009 at 02:04. Reason: lines reorganised


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
  •