您好我有一个插入一些数据的查询,然后检索插入的ID。 然后,inert_id用于另一个连接2个表的查询中。 数据正在插入但未显示。
欢迎任何帮助,
麦克
<?php
public function saveRecord(){
$this->load->helper('date');
$data = array(
'user' => $this->input->post('user'),
'qId' => $this->input->post('id'),
'date' => now()
);
$sql = $this->db->insert('videos',$data);
$answer_id = $this->db->insert_id();
if($this->db->affected_rows() != 1)
{
echo "failed to add to table";
} else {
$this->db->where('id', $answer_id);
$this->db->select('*');
$this->db->from('videos');
$this->db->join('questions', 'questions.id = videos.qId','inner');
$sql2 = $this->db->get();
if($sql2->num_rows() > 0){
foreach($sql2->result() as $r){
?>
<script>
$('#answers_wrapper').append("<div class='answer_recorded_container'></div>");
</script>
<?php
}
} else {
?>
<script>
$('#answers_wrapper').html("<div class='answer_recorded_container'>nothing found!</div>");
</script>
<?php
}
}
}
?>