gpt4 book ai didi

php 数据 varchar 的 substr 函数

转载 作者:行者123 更新时间:2023-11-29 22:05:18 25 4
gpt4 key购买 nike

我有问题,我想输入数据发票号码,当我在我的计算机中尝试使用 phpmyadmin 版本 5.6.16 时,它可以工作,但我上传到 cpanel phpmyadmin v 5.5 它不工作。

V 5.6.16 中的结果:

- INV0001
- INV0002
- INV0003

Cpanel/Hosting 中的结果。 V 5.5:

- INV0001
- INV0001
- INV0001

重复了,怎么解决?先谢谢了。

<?php
$query = "SELECT max(invoice) AS invoice FROM orders";
$hasil = mysql_query($query);
$data = @mysql_fetch_array($hasil);
$lastinv = $data['invoice'];
$nextInv= (int) substr($lastinv, 3, 4);
$nextInv++;
$char = "INV";
$newInvoice = $char . sprintf("%04s", $nextInv);
?>

最佳答案

您可以尝试以下代码以避免重复记录:

$query = "SELECT max(invoice) AS invoice FROM orders";
$hasil = mysql_query($query);
$data = @mysql_fetch_array($hasil);
$lastinv = $data['invoice'];
$nextInv= (int) substr($lastinv, 3, 4);
$nextInv++;
$char = "INV";

$i = 1;
while(true) // eliminating duplicacy
{
$newInvoice = $char . sprintf("%04s", $nextInv);

$query = "SELECT * FROM orders where invoice = ".$newInvoice;
$hasil = mysql_query($query);
$data = @mysql_fetch_array($hasil);
if(empty($data))
break;
$i++;
}

关于php 数据 varchar 的 substr 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32197056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com