参加した後、テーブルのPK ID値の代わりに、外部キーの値を取得する方法はありますか?CodeIgniterの

マダラコード:

私は私のPK値を取得する必要があります。

今、私が持っている問題は、私はフェッチしていた値が外部キーです。どのように私はPK ID値を取得することができますか?

視覚的なプレゼンテーションは、のために:私の問題を見てください

私のUIと問題: ここでは、画像の説明を入力します。

ので、すべての値は1、外部キーの値です。どのように私はそれを変更することができ12PKの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();

クエリごとのような結果を達成するために

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=298462&siteId=1