Jump to content

Create unique order number


kessels1234

Recommended Posts

Hi,

 

Does anyone know a good way to create a good ordernumber.

I have a table with a record: order_num I want it to be a reasonable number. I know I could do something like this:

$order_num .= date("Ymdhis");

 

But this returns a much too long number. I guess what I want is something like this:

year+month+day+number

 

number should be incremented by, let's say 5

Example ordernumber should look like this:

2010030115 and the next ordernumber should be

2010030120

 

so in the database there shoul be a lookup on the last ordernumber.

 

Any ideas? Hope this story makes sense.

 

Thanks in advance

Danny

 

 

Link to comment
Share on other sites

you can simply rely on an auto_increment ID column of your orders table and add say 10000 to it for the displayed order number.

 

I would think that having gaps of 5 numbers could lead to confusion with future tracking of order information.

Link to comment
Share on other sites

you can simply rely on an auto_increment ID column of your orders table and add say 10000 to it for the displayed order number.

 

I would think that having gaps of 5 numbers could lead to confusion with future tracking of order information.

 

Agreed you can use like this

$today = mktime(0,0,0,date("m"),date("d"),date("Y"));
$ordernumber = date("Ymd", $today);
$iniatialcheck=strlen($ordernumber);
if($iniatialcheck != 
{
$firstorder = "1";
$ordernumber1 = "$ordernumber$firstorder";
} else {
// increment valuses in database somthing like mysql set ordernumber=ordernumber+1
}

Link to comment
Share on other sites

you can simply rely on an auto_increment ID column of your orders table and add say 10000 to it for the displayed order number.

 

I would think that having gaps of 5 numbers could lead to confusion with future tracking of order information.

 

Agreed you can use like this

$today = mktime(0,0,0,date("m"),date("d"),date("Y"));
$ordernumber = date("Ymd", $today);
$iniatialcheck=strlen($ordernumber);
if($iniatialcheck != 
{
$firstorder = "1";
$ordernumber1 = "$ordernumber$firstorder";
} else {
// increment valuses in database somthing like mysql set ordernumber=ordernumber+1
}

***

if($iniatialcheck == 
{

Link to comment
Share on other sites

Thanks for all the help.

 

inversesoft123: I (partially) see what you mean but I don't know how to implement this (further)(still newbee who's learning)

 

Solution I came up for now =:

 

$maxsql = "SELECT MAX(repair_id) FROM repair";
$maxresult = mysql_query($maxsql);
$maxrow = mysql_fetch_assoc($maxresult);

$max_id = $maxrow['MAX(repair_id)'];

 

Get the latest repair_id in the database

 

and

 

$order_num = date("Ymds");
$order_num .= $max_id;

 

to create the ordernumber and then store it in the database with all the rest of the formdetails.

 

Love to have comment on this.

 

Thanks

Danny

Link to comment
Share on other sites

if you use Ymds then its very difficult and confusing for you to manage ordernumbers.

What i men is if you want to include todays date into the order number then

 

$today = mktime(0,0,0,date("m"),date("d"),date("Y"));
$ordernumber = date("Ymd", $today);  // newly generated order number

// echo "$ordernumber";  //gives ordernumber of 8 digit like 20100203
// now we have to add todays first order into this 8 digit order number

  $selectorder="SELECT * from my_orders ORDER by id DESC LIMIT 1";
  $selectorder2=mysql_query($selectorder);
  $selectorder3=mysql_fetch_array($selectorder2);
  $mylastordernumb = substr($selectorder3[onumber],0,;
if($mylastordernumb != $ordernumber)
{
$iniatialcheck=strlen($ordernumber);  //we check length of order number
if($iniatialcheck == 
{
$firstorder = "1";
$ordernumber1 = "$ordernumber$firstorder";
mysql_query("INSERT INTO my_order SET onumber='".$ordernumber1."', todays="'.$firstorder.'");
} else {
$firstorder = $selectorder3[todays]++;
$ordernumber1 = "$ordernumber$firstorder";
mysql_query("INSERT INTO my_order SET onumber='".$ordernumber1."', todays="'.$firstorder.'");
// thats it 
}
}

Link to comment
Share on other sites

Is there some reason you not simply using a numeric value and letting an auto_increment field in your table to do this for you?

 

If you use anything that SELECTs the current highest value, modifies it, and INSERTs the new value, you will need to lock the table so that concurrent operations won't accidentally use the same new value.

Link to comment
Share on other sites

The reason I want a real unique number is that I think that it is nobodies business to see(count) how much business we're doing on the repairs. We do repairs for customers on a regular basis. So one customer can come back 2 or 3 times within a month. If you have a simple increment by 1 a customer can see how much repairs we had since his last visit. This is not a welcome situation and that's the reason why I need a unique number.

 

Hope this clears the questions and if anyone has some good alternatives I'd love to hear them.

 

Thanks,

Danny

Link to comment
Share on other sites

Your returning customer would see a new number whatever system you choose to use. He has no way of knowing your system, and if it is a sequential number or not. You may have a totally different system in place and he might still think it is a sequential number. The one major advantage of a sequential number is for your internal auditing

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.