gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 04:54:14 26 4
gpt4 key购买 nike

代码如下:

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

设置答案 ID 会删除问题 ID 的值,然后在更新数据库时答案 ID 也没有值。即使它之前确实如此。

最佳答案

$this->db->insert_id() 方法在执行数据库插入(顾名思义)时检索 ID。

您在更新后使用它,这就是您的 $question_id 出现问题的原因(我认为它会被设置为 FALSE,但我不确定该方法在什么时候返回什么在错误的上下文中调用)。当您进行最后一次更新时,您将其用作 WHERE 条件,如果未设置...

并不是你对 insert_id() 的第二次调用消除了第一个,我怀疑更像是第一个已经 NOT SET(或 FALSE)

关于php - $this->db->insert_id() 似乎抹去了我以前的 insert_id 变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8225054/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com