Jump to content

auto increment problem


gavin1512

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/86204-auto-increment-problem/
Share on other sites

Tell your client they're a pain :P

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.