You can use session in Php for this. In session for each user will have order_id. You can also use cookies. You can easily maintain session variable for a user. This session variable contain the order_id value.
what is latest order_id, store to database. when new user come then read that order id from database and increment it then assign to user. After update to database.
what is session-
When you work with an application, you open it, do some changes, and
then you close it. This is much like a Session. The computer knows who
you are. It knows when you start the application and when you end. But
on the internet there is one problem: the web server does not know who
you are or what you do, because the HTTP address doesn't maintain
state.
Session variables solve this problem by storing user information to be
used across multiple pages (e.g. username, favorite color, etc). By
default, session variables last until the user closes the browser.
So; Session variables hold information about one single user, and are
available to all pages in one application.
I am settng an example only. It may be differ for your case.
mysql > desc order_id_generate;
+-------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
+-------+---------+------+-----+---------+----------------+
<?php
// Start the session
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(isset($_SESSION['order_id']) && !empty($_SESSION['order_id'])) {
echo "Already ordered set and not empty ! ".$_SESSION[`order_id`];
}
else {
$query = "INSERT INTO order_id_generate VALUES ()";
$mysqli->query($query);
$temp=$mysqli->insert_id;
// set the new order
$_SESSION['order_id']=$temp;
echo "Ordered set and not empty ! ".$_SESSION[`order_id`];
}
$conn->close();
?>
</body>
</html>
more @ w3school and php mannual