2016-03-19 68 views
1

我正在成功從名爲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>

但我無法以表格格式顯示數據。我在做什麼錯更換預定數據顯示這樣enter image description here

回答

0

請試試這個在您的視圖文件...

<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> 

希望這會幫助你。

+0

您必須製作正確的表格並設置適當的結果集。 –

+0

謝謝桑傑:)。 –