如何使用PHP将下一个序列号与最后一个增量值更改?

How to alter next sequence number with last increment value using PHP?

提问人:numuki sdf 提问时间:9/29/2019 最后编辑:suspectusnumuki sdf 更新时间:9/29/2019 访问量:282

问:

我想在每个循环之后更改下一个序列号。如何使用 PHP 获取最后一个递增的数字?

$incjobid = $job_Id++;//1,2,3,4,我需要用 5 更改下一个序列号。 一次插入 4 条记录,id 为 1,2,3,4,下一个序列号应该是 5.如何设置?

$this->db->select('NEXT VALUE FOR job_seq as jobid');
$queryjobid = $this->db->get();                     
foreach ($queryjobid->result_array() as $row) {
    $job_Id = $row['jobid'];
}


   if (is_array($this->input->post('getschedule'))) {
                foreach($this->input->post('getschedule') as $value) {

                    //Auto generate JOB SCHEDULE HERE
                    $this->db->insert('job_schedule', array(
                        'jobschedule_id' => $jobschedule_id,
                        'Activity_area_id' => $Activity_area_id,
                        'Contract_id' => $this->input->post('getcontract_id'),
                        'job_freq_id' => $this->input->post('getcontractbranch_freq'),
                        'job_schedule_dates' => $value[0], //assume array form like your screenshot
                        'job_schedule_frequency' => $value[1],
                        'created_at' =>$created_Dt
                    ));


                    //Auto generate JOB HERE
                    $incjobid = $job_Id++;
                    $this->db->insert('job', array(
                        'Job_id' => $incjobid,
                        'Job_no' => $incjobid,
                        'Contract_id' => $this->input->post('getcontract_id'),
                        'Job_Date' => $value[0],
                        'Start_time' => '08:30',
                        'Activity_Area_id' => $Activity_area_id,
                        'created_Dt' => $created_Dt,
                        'status' => 'open',
                        'sr_available' => '0'
                        //'end_time' => $this->input->post('getEnd_Time') ?: null,
                        //'team_id' => $this->input->post('getassignedtoJob'),
                        //'type_of_services_id' => $this->input->post('gettypeofserviceJob'),
                        //'type_of_visit_id' => $this->input->post('gettypeofvisitjob')
                    ));
                }


                $insert_id = $this->db->insert_id(); 
                //$this->db->ALTER('SEQUENCE job_seq RESTART WITH 547');
                    //$queryjobalter = $this->db->get();
                    //$queryjobalter->result();

            }
php sql-server codeigniter 序列

评论

0赞 numuki sdf 9/29/2019
谁能帮忙做这件事?
0赞 numuki sdf 9/29/2019
@MadhurBhaiya正在使用 NEXT 序列号知道
0赞 numuki sdf 9/29/2019
@MadhurBhaiya现在的问题是下一个序列值是错误的,所以当我进行下一个交易时,它显示重复的 ID..(表示表中已经退出了 id)
0赞 numuki sdf 9/29/2019
@MadhurBhaiya所以我想在停止增量值加 1 之后做,我需要设置下一个序列值
2赞 Aksen P 9/29/2019
您知道可以在您的表中创建自动递增字段吗?php中没有任何魔法吗?

答: 暂无答案