kessels1234 Posted March 1, 2010 Share Posted March 1, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/193760-create-unique-order-number/ Share on other sites More sharing options...
jl5501 Posted March 1, 2010 Share Posted March 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/193760-create-unique-order-number/#findComment-1019827 Share on other sites More sharing options...
inversesoft123 Posted March 1, 2010 Share Posted March 1, 2010 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 } Quote Link to comment https://forums.phpfreaks.com/topic/193760-create-unique-order-number/#findComment-1019835 Share on other sites More sharing options...
inversesoft123 Posted March 1, 2010 Share Posted March 1, 2010 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 == { Quote Link to comment https://forums.phpfreaks.com/topic/193760-create-unique-order-number/#findComment-1019871 Share on other sites More sharing options...
kessels1234 Posted March 1, 2010 Author Share Posted March 1, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/193760-create-unique-order-number/#findComment-1020167 Share on other sites More sharing options...
inversesoft123 Posted March 2, 2010 Share Posted March 2, 2010 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 } } Quote Link to comment https://forums.phpfreaks.com/topic/193760-create-unique-order-number/#findComment-1020359 Share on other sites More sharing options...
PFMaBiSmAd Posted March 2, 2010 Share Posted March 2, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/193760-create-unique-order-number/#findComment-1020360 Share on other sites More sharing options...
inversesoft123 Posted March 2, 2010 Share Posted March 2, 2010 agreed! thats why autoincrement shoud be a best solution Quote Link to comment https://forums.phpfreaks.com/topic/193760-create-unique-order-number/#findComment-1020361 Share on other sites More sharing options...
kessels1234 Posted March 2, 2010 Author Share Posted March 2, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/193760-create-unique-order-number/#findComment-1020668 Share on other sites More sharing options...
jl5501 Posted March 3, 2010 Share Posted March 3, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/193760-create-unique-order-number/#findComment-1020778 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.