Hello everyone I have a problem that does not reflect in a view the data of another associated table, if I show the ID with the reference of the column but I want to give me the names, here is the model: It is a CRUD: The view has to add, edit and delete, when I edit if the data appear, but when I visualize them only the ids appear:
function update_asignacion($id,$params){
$this->db->where('id',$id);
return $this->db->update('asignacion',$params);
}
The index:
function index(){
$data['asignacion'] = $this->Asignacion_model->get_all_asignacion();
$data['_view'] = 'asignacion/index';
$this->load->view('layouts/main',$data);
}
the edit view handler:
function edit($id){
// check if the asignacion exists before trying to edit it
$data['asignacion'] = $this->Asignacion_model->get_asignacion($id);
if(isset($data['asignacion']['id'])){
$this->load->library('form_validation');
$this->form_validation->set_rules('alumno_id','Alumno Id','required');
$this->form_validation->set_rules('curso_id','Curso Id','required');
if($this->form_validation->run()) {
$params = array(
'alumno_id' => $this->input->post('alumno_id'),
'curso_id' => $this->input->post('curso_id'),
);
$this->Asignacion_model->update_asignacion($id,$params);
redirect('asignacion/index');
} else {
$this->load->model('Alumno_model');
$data['all_alumnos'] = $this->Alumno_model->get_all_alumnos();
$this->load->model('Curso_model');
$data['all_cursos'] = $this->Curso_model->get_all_cursos();
$data['_view'] = 'asignacion/edit';
$this->load->view('layouts/main',$data);
}
}else{
show_error('The asignacion you are trying to edit does not exist.');
}
}
and the view (this is the view of the index):
<?php foreach($asignacion as $a){ ?>
<tr>
<td><?php echo $a['id']; ?></td>
<td><?php echo $a['alumno_id']; ?></td>
<td><?php echo $a['curso_id']; ?></td>
<td>
<a href="<?php echo site_url('asignacion/edit/'.$a['id']); ?>" class="btn btn-info btn-xs"><span class="fa fa-pencil"></span> Edit</a>
<a href="<?php echo site_url('asignacion/remove/'.$a['id']); ?>" class="btn btn-danger btn-xs"><span class="fa fa-trash"></span> Delete</a>
</td>
</tr>
<?php } ?>
this is the Edit view:
<div class="form-group">
<select name="alumno_id" class="form-control">
<option value="">select alumno</option>
<?php foreach($all_alumnos as $alumno){
$selected = ($alumno['id'] == $asignacion['alumno_id']) ? ' selected="selected"' : "";
echo '<option value="'.$alumno['id'].'" '.$selected.'>'.$alumno['nombre'].'</option>';
} ?>
</select>
<span class="text-danger"><?php echo form_error('alumno_id');?></span>
</div>
But I already try to place it in the same way in the index and I'm wrong. I would appreciate your help please. Greetings
Screenshots