[英]displaying data in table using codeigniter
表未在表中顯示任何值。 當我做了var_dump($ results)。 它打印為NULL。 由於我是Codeigniter的新手,所以我無法解決此問題。 我不明白,我在哪里弄錯了。 幫我。
查看頁面
<tbody>
<?php
if(!empty($results) ) {
foreach($results as $row) {
echo '<tr>';
echo '<td>'." ".'</td>';
echo '<td>'.$row->FileTitle.'</td>';
echo '<td>'.$row->UploadedFile.'</td>';
echo '<td>'.$row->CreationDate.'</td>';
echo '<td>'.$row->UpdateDate.'</td>';
echo '<td>'." ".'</td>';
echo '</tr>';
}
}?>
</tbody>
控制者
class Welcome extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('news_model');
$this->load->helper('form');
$this->load->library('form_validation');
}
public function member_CAttachments()
{
$data['results'] = $this->news_model->member_MAttachments();
$this->load->view('member/templates/header');
$this->load->view('member/index',$data);
$this->load->view('member/templates/footer');
}
}
模型
class News_model extends CI_Model
{
public function __construct()
{
$this->load->database();
}
public function member_MAttachments()
{
$results = array();
$query = $this->db->get('MemberFileDetails');
if($query->num_rows() > 0)
{
$results = $query->result();
}
return $results;
}
}
相反,您可以使用內置的CI Table
庫在更少的行中完成此操作,
同時支持2.2
和3.x
版本。
像這樣使用
$this->load->library('table');
$this->table->set_heading('FileTitle', 'UploadedFile', 'CreationDate', 'UpdateDate');
$query = $this->db->query('SELECT * FROM MemberFileDetails');
echo $this->table->generate($query);
您的表中有記錄嗎? 如果是的話,請嘗試刪除
if($query->num_rows() > 0)
條件,然后嘗試。
刪除$results = array();
在你的代碼中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.