Jump to content

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.

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.