我拿的是最大发票号。从一个表中递增1,并用递增的值更新相同的表,问题是多个用户正在执行此操作,因此有时它会错过序列,而有时会为不同的作业生成相同的序列。我不能使发票没有字段唯一,因为对于其他工作,它是0。代码是这样的。
$res=mysql_query("select max(invoice_no) from complaints_master");
$result=mysql_fetch_array($res);
$code_id=$result[0]+1;
// update invoice details in complaint master
$usr="update complaints_master set invoice_no='$code_id', invoice_flag='1', invoice_date='$today', invoice_total_amt='$_POST[final_total]' where job_no='$_REQUEST[job_no]'";发布于 2013-05-03 02:41:36
您需要将事务级别设置为SERIALIZABLE,以确保每个MAX(invoice_no)+1向客户端返回一个惟一的值。不知道如何在使用PHP时做到这一点,但这里是MySQL文档:MySQL SET TRANSACTION Syntax。
https://stackoverflow.com/questions/16345123
复制相似问题