Código Madara:
Tengo que buscar mi valor PK.
En este momento, el problema que tengo es el valor que estoy retracto es la clave externa. ¿Cómo puedo ir a buscar el valor id PK?
Para REPRESENTACIÓN visual: Mira mi problema
Mi interfaz de usuario y un problema:
por lo que todos los valores son 1
que es el valor de las claves externas. ¿Cómo lo cambio a 1
, 2
etc., que es el valor id PK?
Mi modelo que tiene consulta de combinación
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();
}
Controlador
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');
}
Ver a mi mesa y el id que debería ir a buscar:
Ver
<?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:
trate de usar
$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();
para lograr resultados como por consulta