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

标签 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');

最佳答案

你可以试试

$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');

关于php - 通过 CodeIgniter 中的代码在收据表中自定义自动编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40056396/

相关文章:

php - 带有 Bootstrap 4 的 Codeigniter 3 分页类

php - 在 Codeigniter 的库中加载 View 页面

javascript - jQuery.get 读取文件并将数据放入表单中

php - 将用户 ID 存储或获取为 PHP session 变量

MYSQL RIGHT JOIN 过滤器不起作用

mysql - 如何在 zend2 中编写复杂的 sql 查询

codeigniter - 路线不起作用

php - mysql 更新查询未运行

php - 警告:DOMDocument::loadHTML(): htmlParseEntityRef:在实体中期望 ';',

mysql - 自动更新数据库列