マダラコード:
私は私のPK値を取得する必要があります。
今、私が持っている問題は、私はフェッチしていた値が外部キーです。どのように私はPK ID値を取得することができますか?
視覚的なプレゼンテーションは、のために:私の問題を見てください
ので、すべての値は1
、外部キーの値です。どのように私はそれを変更することができ1
、2
PKのid値であるなど?
クエリに参加している私のモデル
public function get_questions($id){
$this->db->select('*');
$this->db->from('answers');
$this->db->join('questions', 'answers.question_id = questions.id');
$this->db->where('questions.id', $id);
$query = $this->db->get();
return $result = $query->result_array();
}
コントローラ
public function edit($id)
{
$data['questions'] = $this->post_model->get_questions($id);
$this->load->view('templates/header');
$this->load->view('teachers/edit', $data);
$this->load->view('templates/footer');
}
私のテーブルと私はフェッチすべきIDを参照してください。
見る
<?php echo form_open('posts/update'); ?>
<!-- <input type="hidden" name="id[]" value="<?php echo $posts['id']; ?>" /> -->
Question:
<input type="text" name="question" class="form-control" value="<?php echo $posts['question']; ?>" /><hr>
Answers:
<?php foreach($questions as $question): ?>
<input type="text" name="id[]" value="<?php echo $question['id']; ?>" /><hr>
<input type="text" name="answer[]" class="form-control" value="<?php echo $question['answer']; ?>" /><hr>
<?php endforeach; ?>
<hr>
<input type="submit" class="btn btn-success" value="Save Changes">
</form>
サンディープモーダカ:
使用してみてください
$this->db->select('answers.id,answers.answer,answers.question_id,answers.correct,answers.type_id');
$this->db->from('answers');
$this->db->join('questions', 'answers.question_id = questions.id');
$this->db->where('questions.id', $id);
$query = $this->db->get();
return $result = $query->result_array();
クエリごとのような結果を達成するために