所以我想加入3张桌子.
我正在构建一个app i Codeigniter,我有3个表
客户:
-id
-phone_number
-hospital_id
-smc_status
-testing_center_id
医院
-id
-name
Testing_center
-id
-name
在模型中,我有这个:
public function get_clients()
{
if($slug === FALSE)
{
$this->db->select('clients.*');
$this->db->from('clients');
$this->db->join('hospital', 'clients.id = hospital.id');
$this->db->join('testing_center', 'clients.id = testing_center.id');
$query = $this->db->get();
return $query->result_array();
}
$query = $this->db->get_where('clients');
return $query->row_array();
}
Run Code Online (Sandbox Code Playgroud)
在视图中我有:
<tbody>
<?php foreach ($clients as $client_item): ?>
<tr>
<td><?php echo $client_item['phone_number'] ?></td>
<td><?php echo $client_item['smc_status'] ?></td>
<td><?php echo $client_item['hospital_id'] ?></td> //i wish to have the hospital name here
<td><?php echo $client_item['testing_center_id'] ?></td> …Run Code Online (Sandbox Code Playgroud)