如何在自动增量中将我的ID从12-09CB1变为12-09CB0001?

时间:2012-09-28 07:00:02

标签: php phpmyadmin

您好我使用了以下代码

$last_id=mysql_query("select * from complaint_list order by complaint_id Desc Limit 1");
$complaint_last=mysql_fetch_array($last_id);

$complaintid=$complaint_last['complaint_id'];
$complaintid = str_pad($id, 4, '0');
$year = substr($get[0],2,2);
$complaint_number=$year."-".$get[1]."CB".$complaintid;

mysql_query("insert into complaint_list(complaint_number, sap_number, complaint_type, circle_id) values('" . $complaint_number . "','" . $_POST['sap_number'] . "', 'DU', " . $_POST['circle'].")");

它一直显示为12-09CB0000。

请帮帮我

1 个答案:

答案 0 :(得分:1)

嗨,我解决了这个问题,

只需替换此代码

$last_id=mysql_query("select *,lpad(complaint_id,4,'0') as cid from complaint_list order by complaint_id Desc Limit 1");
    $complaint_last=mysql_fetch_array($last_id);
    $complaintid=$complaint_last['cid'];
    $complaintid = str_pad($complaintid, 4, '0');
    $year = substr($get[0],2,2);
    $complaint_number=$year."-".$get[1]."CB".$complaintid;