gavin1512 Posted January 15, 2008 Share Posted January 15, 2008 Good evening All, I have a slight issue with generating an auto increment that adds on the end of two variables. Basically I have an order ID which is made up of a username and date: $order = $username.date("d-M-Y"); But this restricts the users to one order per day, can some one please assist me to have a single digit after the username and date which increases if that order ID exists. Thank You Quote Link to comment https://forums.phpfreaks.com/topic/86204-auto-increment-problem/ Share on other sites More sharing options...
GingerRobot Posted January 15, 2008 Share Posted January 15, 2008 Is there any particular reason why you're giving your orders and order ID like this? Things would be much simpler if you just used a number. Quote Link to comment https://forums.phpfreaks.com/topic/86204-auto-increment-problem/#findComment-440256 Share on other sites More sharing options...
gavin1512 Posted January 15, 2008 Author Share Posted January 15, 2008 Unfortunately not, the system is due to replace a current basic paper based system and my client would like to keep the format of the order ID Quote Link to comment https://forums.phpfreaks.com/topic/86204-auto-increment-problem/#findComment-440257 Share on other sites More sharing options...
almystersv Posted January 15, 2008 Share Posted January 15, 2008 I agree, Why not change the orderID to numbers??? Quote Link to comment https://forums.phpfreaks.com/topic/86204-auto-increment-problem/#findComment-440265 Share on other sites More sharing options...
PFMaBiSmAd Posted January 15, 2008 Share Posted January 15, 2008 If we knew where and how the existing order numbers were stored (database, flat-file database...), it would help. Quote Link to comment https://forums.phpfreaks.com/topic/86204-auto-increment-problem/#findComment-440279 Share on other sites More sharing options...
GingerRobot Posted January 15, 2008 Share Posted January 15, 2008 Tell your client they're a pain Anyways, i'd advise you to keep the bits of information separate in the database, and only join them together to form the order ID when you output the data. So, you'll have 3 columns: username,date,order_today (or whatever you prefer). You can then do something like: <?php $sql = "SELECT MAX(order_today) FROM tbl WHERE username = '$user' AND `date` = DATE(NOW())"; $result = mysql_query($sql);; $order_today = mysql_result($sql,0) + 1; $sql = "INSERT INTO tbl (username,`date`,order_today) VALUES ('$user',DATE(NOW()),$order_today)"; mysql_query($sql); ?> Edit: PFMaBiSmAd has a valid point. I've assumed you're using a database. Quote Link to comment https://forums.phpfreaks.com/topic/86204-auto-increment-problem/#findComment-440290 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.