Is there a way to fetch table PK id value instead of foreign key value after Join? Codeigniter

Madara Code :

I need to fetch my PK value.

Right now, the problem that I have is the value I am fetching is the foreign key. How can I fetch PK id value?

For visual representaion: Look at my problem

My UI and problem: enter image description here

so all values are 1 which is the value of foreign keys. How can I change it to 1 , 2 etc. which is PK id value?

My Model that has join query

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();
}

Controller

   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');   
    }

See my table and the id I should fetch:

enter image description here

View

<?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>
Sandeep Modak :

try using

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

to achieve results as per query

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=297460&siteId=1