[英]I dont know what is wrong with my html and php code.It gives Error:Query was empty
[英]codeigniter problem, I dont know what's wrong with my MVC
所以我不知道是我的 controller 還是我的 CodeIgniter 框架中的 model 出了什么問題,請幫忙。 在我看來,我的表沒有從我的數據庫中獲取數據。
我已經嘗試了我在 stackoverflow 中看到的所有內容,但我無法讓它工作,但這是我的原始代碼。
這是我的controller :
public function index(){
$data['suppliers'] = $this->dashboard_model->readSupplier();
$data['items'] = $this->dashboard_model->readItem();
$data['users'] = $this->dashboard_model->readUser();
$data['units'] = $this->dashboard_model->readUnit();
$data['logs'] = $this->dashboard_model->readLogs();
$this->global['pageTitle'] = 'Dashboard';
$this->loadViews("pages/dashboard", $this->global, $data);
這是我的model :
class Dashboard_model extends CI_Model{
function readSupplier(){
$this->db->from('suppliers');
$this->db->limit(5);
$this->db->order_by('supplier_id', 'DESC');
$query = $this->db->get();
$result = $query->result();
return $result;
}
function readItem(){
$data = array(
'categories.category_name',
'items.item_id',
'items.category_id',
'items.brand_name',
'items.model',
'items.serial',
'items.unit_price',
'items.status',
'items.location_id',
'suppliers.supplier_id',
'suppliers.supplier_name'
);
$this->db->select($data);
$this->db->from('items');
$this->db->join('categories', 'categories.category_id =
items.category_id', 'left');
$this->db->join('suppliers', 'suppliers.supplier_id =
items.supplier_id', 'left');
$this->db->limit(10);
$this->db->order_by('item_id', 'DESC');
$query = $this->db->get();
$result = $query->result();
return $result;
}
function readUser(){
$this->db->from('users');
$this->db->limit(10);
$this->db->order_by('userId','DESC');
$query = $this->db->get();
$result = $query->result();
return $result;
}
function readUnit(){
$data = array(
'l.location_name',
'su.su_id',
'su.unit',
'su.motherboard',
'su.processor',
'su.ram',
'su.hdd',
'su.video_card',
'su.lan_card',
'su.power_supply',
'su.location_id',
'su.comment',
);
$this->db->select($data);
$this->db->from('system_unit as su');
$this->db->join('locations as l', 'l.location_id=su.location_id', 'left');
$this->db->limit(10);
$this->db->order_by('unit', 'DESC');
$query = $this->db->get();
$result = $query->result();
return $result;
}
function readLogs(){
$this->db->from('activities as a');
$this->db->join('users as u', 'u.userId=a.userId', 'left');
$this->db->limit(10);
$this->db->order_by('userId', 'DESC');
$query = $this->db->get();
$result = $query->result();
return $result;
}
?>
這是我的觀點:
<th>User ID</th>
<th>Full Name</th>
<th>Email</th>
</thead>
<tbody>
<?php
if(!empty($users)):
foreach($users as $user): ?>
<tr>
<td><?php echo $user->userId; ?></td>
<td><?php echo $user->firstname." ".$user->lastname; ?></td>
<td><?php echo $user->email; ?></td>
</tr>
<?php endforeach;
endif;
?>
問題出在您的controller方法中: loadViews
您可以通過此鏈接查看如何加載視圖的方式。
我認為在model中一切都很好。 因此,您需要檢查方法loadViews
。 而且,如果你真的想看到一些結果,你可以替換下一個:
$this->global['pageTitle'] = 'Dashboard';
$this->loadViews("pages/dashboard", $this->global, $data);
和
$this->load->view('pages/dashboard',$data);
注意:閱讀如何使用此方法load->view
的第三個參數,它的值可以是true
或false
,默認為false
。
我現在實際上進入了它的工作,我現在遇到的唯一問題是它給了我一個關於我的 readLogs function 的錯誤,但是如果我刪除 readLogs function,所有表都將顯示除日志歷史記錄之外的數據。 順便說一句,這是錯誤。
發生數據庫錯誤錯誤號:1052
order 子句中的列“userId”不明確
SELECT * FROM activities
a
LEFT JOIN users
作為u
ON u
。 userId
= a
。 userId
ORDER BY userId
DESC LIMIT 10
文件名:E:/Xammp2/htdocs/cri-marc/system/database/DB_driver.php
行號:691
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.