在视图中以表格形式显示结果

时间:2016-03-19 10:46:47

标签: php html codeigniter

我成功地将名为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>
&#13;
&#13;
&#13;

但我无法以表格格式显示数据。我在这里做错了什么。数据显示如下enter image description here

1 个答案:

答案 0 :(得分: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>

希望这会对你有所帮助。