duanshaiduhao2471 2011-11-22 10:07
浏览 182
已采纳

$ this-> db-> insert_id()似乎正在抹去我以前的insert_id变量值

Here is the code:

$the_question = $_POST['question'];
            $the_answer = $_POST['answer'];
            $dummy_num[] = $_POST['dummy_answer_1'];
            $dummy_num[] = $_POST['dummy_answer_2'];
            $dummy_num[] = $_POST['dummy_answer_3'];
            //Get Hidden Test ID and Q_order
            $test_id = $_POST['test_id'];
            $q_order = $_POST['q_order'];
            //Submit Question
            $data_submit_q = array (
                'type' => 1,
                'question' => $the_question,
                'done' => 1
            );
            $this->db->where('test_id', $test_id);
            $this->db->where('q_order', $q_order);
            $this->db->update('questions', $data_submit_q);
            $question_id = $this->db->insert_id();
            $time_created = date('Y-m-d H:i:s');
            //Submit Answer 
            $data_submit_a = array (
                'test_id' => $test_id,
                'question_id' => $question_id,
                'option' => $the_answer,
                'company_id' => $data['company']->id,
                'job_id' => $data['session_job_id'],
                'time_created' => $time_created
            );
            $this->db->insert('options', $data_submit_a);
            $answer_id = $this->db->insert_id();

            //Let question know that answer is right.
            $data_submit_qr = array (
                'answer_id' => $answer_id
            );

            $this->db->where('id', $question_id);
            $this->db->where('test_id', $test_id);
            $this->db->update('questions', $data_submit_qr);

Setting the answer id removes the value of the question id, then on updating the database the answer id has no value also. Even though it does right before.

  • 写回答

2条回答 默认 最新

  • dragon8837 2011-11-22 10:23
    关注

    The method $this->db->insert_id() retrieves the ID when performing database inserts (as the name hints).

    You're using it after an update, that's why your $question_id gives problems (I think it would be set to FALSE, but I don't know for sure what does that method return when called on the wrong context). WHen you do your last update you use this as a WHERE condition, and if it is not set...

    It's not that your second call to insert_id() wipes out the first, I suspect is more like the first one is already NOT SET (or FALSE)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求
  • ¥15 SpringSecurityOauth2登陆前后request不一致
  • ¥15 禅道二次开发编辑版本,上传不了发行包