Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Mysql表中的自定义自动增量_Php_Mysql - Fatal编程技术网

Php Mysql表中的自定义自动增量

Php Mysql表中的自定义自动增量,php,mysql,Php,Mysql,我的表中有三个客户Id,比如A、B、C。我想创建订单表来管理来自这些客户的订单。我想创建orderID列,以便它必须自动递增并附加cunstomer Id,例如orderID列记录: A_1 --->A's 1st order, A_2 --->A's 2nd order, B_1 --->B's 1st order, C_1 --->C's 1st order, A_3 --->A's 3rd order, C_2 --->C's 2nd ord

我的表中有三个客户Id,比如A、B、C。我想创建订单表来管理来自这些客户的订单。我想创建orderID列,以便它必须自动递增并附加cunstomer Id,例如orderID列记录:

A_1  --->A's 1st order,
A_2  --->A's 2nd order,
B_1  --->B's 1st order,
C_1  --->C's 1st order,
A_3  --->A's 3rd order,
C_2  --->C's 2nd order,
C_3  --->C's 3rd order,
B_2  --->B's 2nd order,
A_4  --->A's 4th order,
A_5  --->A's 5th order
这使您可以轻松地插入订单,而无需考虑生成的标识符。创建的附加
行将允许您对它们进行排序,并为它们提供您想要的编号

$result = $mysqli->query("SELECT * FROM `orders` WHERE `customer_id` = 1 ORDER BY `created`");

$orders = array();
while ($row = $result->fetch_assoc()) {
    $orders[] = $row;
}

echo count($orders) , PHP_EOL; // 42

foreach ($orders as $delta => $order) {
    echo "Your order #" , ($delta + 1) , " with the unique identifier {$order["order_id"]}." , PHP_EOL;
}

仅举一个例子。

我希望各个客户的订单id应该是串行的。如果我查询特定客户的订单表,则必须显示序列订单号。。。。。
$result = $mysqli->query("SELECT * FROM `orders` WHERE `customer_id` = 1 ORDER BY `created`");

$orders = array();
while ($row = $result->fetch_assoc()) {
    $orders[] = $row;
}

echo count($orders) , PHP_EOL; // 42

foreach ($orders as $delta => $order) {
    echo "Your order #" , ($delta + 1) , " with the unique identifier {$order["order_id"]}." , PHP_EOL;
}