我遇到了一個問題,即我的數據庫中的數據未顯示在我的視圖中。據我所知,我的控制器,型號和視圖設置正確。我之前完成了這個工作,所以我知道需要什麼,但是我找不到我的舊文件。我希望你們能幫忙?未顯示在視圖中的Codeigniter數據庫值
控制器:
<?php
if(!defined('BASEPATH')) exit('Hacking Attempt: Get out of the system ..!');
class C_Live extends CI_Controller
{
function C_Live(){
parent::__construct();
$this->load->model('M_live');
}
public function index(){
$query = $this->M_live->getUpgrades();
if(isset($query)){
$data['upgrades'] = $query;
}
$this->load->view('Test', $data);
}
}
?>
型號:
<?php
if(!defined('BASEPATH')) exit('Hacking Attempt: Get out of the system ..!');
class M_live extends CI_Model
{
function M_live()
{
parent::Model();
}
function getUpgrades()
{
$query = $this->db->get('live_client_trust_versions');
// Produces: SELECT * FROM client_trust_versions
return $query->num_rows() > 0 $query->result() : NULL;
}
}
?>
查看:
<table>
<tr>
<th>ID</th>
<th>Client Name</th>
<th>App Server</th>
<th>Instance Name</th>
<th>BankStaff Server</th>
<th>SQL Server</th>
<th>Instance</th>
<th>Health Roster Version</th>
<th>Employee Online Version</th>
<th>Roster Perform</th>
<th>BankStaff Version</th>
<th>SafeCare Version</th>
<th>E-Expenses</th>
</tr>
<?php
if(isset($upgrades)){
//If no rows were found $upgrades will be NULL and isset() will return false.
//Therefore, you never try to address an undefined variable.
foreach($upgrades as $upgrade){?>
<tr>
<td><?php=$upgrade->ID;?></td>
<td><?php=$upgrade->Client_Name?></td>
<td><?php=$upgrade->App_Server?></td>
<td><?php=$upgrade->Instance_Name?></td>
<td><?php=$upgrade->BankStaff_Server?></td>
<td><?php=$upgrade->SQL_Server;?></td>
<td><?php=$upgrade->Instance;?></td>
<td><?php=$upgrade->Health_Roster_Version;?></td>
<td><?php=$upgrade->Employee_Online_Version;?></td>
<td><?php=$upgrade->Roster_Perform_Version;?></td>
<td><?php=$upgrade->BankStaff_Version;?></td>
<td><?php=$upgrade->SafeCare_Version;?></td>
<td><?php=$upgrade->E-Expenses;?></td>
</tr>
<?php }}?>
</table>
The result I'm getting in my view.
閱讀這個http://w3code.in/2015/ 10 /如何插入和選擇數據從數據庫中codeigniter初學者指南/ – Ricky