【发布时间】:2019-11-24 22:15:29
【问题描述】:
我在数据库中有一个如下表
id | touserid | data
1 2 a:1:{i:0;s:10:"INV-000001";}
2 2 a:1:{i:0;s:10:"INV-000003";}
3 2 a:1:{i:0;s:15:"The Mej Hotel";}
4 1 a:5:{i:0;s:28:"Total Goalsi:1;s:7:"6250000";}
5 1 a:1:{i:0;s:10:"INV-000007";}
我想将该数据插入到 html 中的表格中,如下所示
id | touserid | data
1 2 INV-000001
2 2 INV-000003
3 2 The Mej Hotel
4 1 Total Goals : 6250000
5 1 INV-000007
但是当我尝试使用 unsenrialize 时,它只是显示如下所示的数组值
Array
如何将数据显示到 html 表格中?
这是我的模型代码
public function getAllNotifications()
{
return $this->db->get('tblnotifications');
}
这是我的控制器代码
$data['notifications'] = $this->Sales_model->getAllNotifications()->result();
$this->load->view('admin/sales/sales', $data);
这是我的视图代码
<table class="table table-dark">
<tbody>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">To ID</th>
<th scope="col">Notification</th>
</tr>
</thead>
<tbody>
<?php foreach($notifications as $notif){ ?>
<tr>
<td><?php echo $notif->id ?></td>
<td><?php echo $notif->touserid ?></td>
<td><?php echo unserialize($notif->data) ?></td>
</tr>
<?php } ?>
</tbody>
</table>
【问题讨论】:
-
:-
var_dump(unserialize($notif->additional_data));的输出是什么?向我们展示。你想如何在表格中表示它?也告诉我们 -
嗨@AnantSingh---AlivetoDie 它显示的数组值类似于这个数组(1) { [0]=> string(10) "INV-000001" }
-
那么你想通过这个数组显示什么输出。将其添加到您的问题中
-
在名为
data的数据库表字段中,视图中additional_data- 是否正确? -
为什么要以序列化的方式存储这种数据?为什么不以您希望输出的方式存储它,例如
Total Goals : 6250000而不是a:5:{i:0;s:28:"Total Goalsi:1;s:7:"6250000";}
标签: php html mysql codeigniter serialization