0
Hello!
In the controller
I have the following:
public function index() {
$data['demandas'] = $this->demandas_model->get_demandas();
$data['main_view'] = 'demandas/index';
$this->load->view('layouts/main', $data);
}
In the model
in function get_demandas
I have the following:
public function get_demandas() {
$query = $this->db->get('demandas');
return $query->result();
}
And in the view
I display as follows:
<?php foreach($demandas as $demanda): ?>
<tr>
<?php echo "<td><a href='". base_url()."index.php/demandas/edit_view/". $demanda->da_id ."'>".$demanda->da_id."</a></td>" ?>
<?php echo "<td>".$demanda->us_id."</td>" ?>
<?php echo "<td>".$demanda->da_descricao."</td>" ?>
<?php echo "<td>".$demanda->da_data."</td>" ?>
// mais código
Where it is written $demanda->us_id
, instead of displaying the code, I need to display the user name.
In the model, in the function get_demandas
, return me the id
and the nome
user need to return through another call from another model and put in the $data['demandas']
, but I don’t know how to put in the view, through the function index
of controller
.
This is the function
which returns the user data, from model
:
public function get_usuario($id) {
$this->db->where('us_id', $id);
$query = $this->db->get('usuarios');
return $query->result();
}
Thank you
$demanda->nome
?– rray
I forgot to put another detail, id is a foreign key and through it I need to return the name of another query
– novato
Make a Join there.
– Wallace Maxters
Right, this Join I do in get_demands()? if it were in sql I would, but I’m using codeigniter and getting a little confused
– novato