$ 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.

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)

It seems that there is a bug with insert_id, you can try using:

$query = $this->db->query('SELECT LAST_INSERT_ID()');
  $row = $query->row_array();
  $lastInsertId = $row['LAST_INSERT_ID()'];

Hope it helps