所以我有3個表格我想加入。Codeigniter:加入3個表格並在視圖中顯示數據
我建立一個應用程序,我笨,我有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();
}
在視圖中我有:
<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> //i wish to have the testing center name here
<td><?php echo $client_item['language'] ?></td>
<td><a href="#">View</a></td>
</tr>
<?php endforeach ?>
</tbody>
但那是因爲因爲我沒有在第三和第四臺顯示醫院名稱和檢測中心名稱。我怎麼去解決這個問題?我嘗試了一些技術,因爲某些原因似乎沒有工作。請指教
我已經首次提出所有必要的更改由書呆子的建議,以及你的,但我最終得到了HTTP錯誤500,這是爲什麼? – raybesiga
已選中,我犯了一些拼寫錯誤。感謝您的建議! – raybesiga
我正在嘗試填寫表單並將數據返回到數據庫到不同的表中。我會怎麼做呢?我是否首先將表單綁定到數據庫,以便它理解連接,或者我應該將輸入文本置於與數據庫中預期的類似的位置? – raybesiga