通过CodeIgniter中的代码在收据表中自定义自动编号

时间:2016-10-15 07:35:12

标签: php mysql codeigniter auto-increment

我需要自动编号收据数据每当我插入新的行数据时,mysql表中没有增量它仍然保持相同的收据ID 8874 不知道是不是错了

       if ($param1 == 'edit' && $param2 == 'do_update') {
        $data['op_number']   = $this->input->post('op_number');

        $data['name']        = $this->input->post('name');

        $data['ic']          = $this->input->post('ic');

        $data['receipt'] = '8800';
     for($i = 0; $i < 74; $i++) 
 {
$data['receipt']++;
if(substr($data['receipt'], 5) == '100')
{
  continue;
}
}      

        $this->db->insert('invoice', $data);

    $this->session->set_flashdata('flash_message',       get_phrase('invoice_created'));

        redirect(base_url() . 'index.php?receptionist/manage_invoice', 'refresh');

1 个答案:

答案 0 :(得分:0)

你可以尝试一下

$receipt = '8800';

for($i = 0; $i < 74; $i++){
    $receipt++;
    if(substr($receipt, 5) == '100'){
    continue;
    }
}

if ($param1 == 'edit' && $param2 == 'do_update') {
$data= array{
'op_number'  = $this->input->post('op_number'),
'name'       = $this->input->post('name'),
'ic'         = $this->input->post('ic'),
'receipt' = $receipt };




$this->db->insert('invoice', $data);
$this->session->set_flashdata('flash_message',get_phrase('invoice_created'));
redirect(base_url() . 'index.php?receptionist/manage_invoice', 'refresh');