[英]Display results in a table form in view
我成功地將名為user_model的模型中的數據提取到名為login_controller的控制器中。 如下面的user_model所示:
function fetchData()
{
$this->db->select('DeviceName, DeviceType,RegistrationDateTime,LastUpdateDateTime,LastPushNotificationSent');
$query = $this->db->get('userinfo');
$res=$query->result();
if($res)
{
return $res;
}
else
{
return NULL;
}
}
在我的控制器中我有:
function displayDatabase()
{
$data['tableInfo']=$this->user_model->fetchData();
$this->load->view('adminPanel_view',$data);
}
在adminPanel_view我在做什么:
<table class="table table-striped table-bordered table-hover table-full- width" id="sample_1"> <thead> <tr> <th>Serial No.</th> <th class="hidden-xs">Device Name</th> <th>Device Type</th> <th>RegistrationDateTime </th> <th>LastUpdateTime</th> <th>LastPushNotificationSent</th> <th>Actions</th> </tr> </thead> <tbody> <?php //print_r ($tableInfo);exit;?> <?php foreach($tableInfo as $r): ?> <tr> <?php echo $r->DeviceName ?> </tr> <?php endforeach; ?> </tbody> </table>
請在您的視圖文件中嘗試此操作...
<table class="table table-striped table-bordered table-hover table-full- width" id="sample_1">
<thead>
<tr>
<th>Serial No.</th>
<th class="hidden-xs">Device Name</th>
<th>Device Type</th>
<th>RegistrationDateTime </th>
<th>LastUpdateTime</th>
<th>LastPushNotificationSent</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php //print_r ($tableInfo);exit;?>
<?php foreach($tableInfo as $r): ?>
<tr>
<td><?php echo $r->no ?></td>
<td><?php echo $r->DeviceName ?></td>
<td><?php echo $r->DeviceType ?></td>
<td><?php echo $r->RegistrationDateTime ?></td>
<td><?php echo $r->LastUpdateTime ?></td>
<td><?php echo $r->LastPushNotificationSent ?></td>
<td><?php echo $r->Actions ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
希望這會幫助你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.