我在通过 Codeigniter/MySQL 从图像数组中提取值时遇到问题。所以我的数据库中有一个名为“image”的表,如果我回显它,我会得到以下代码:
{"f01efdf6fe3b2bb387d3094aa701203f":{"filename":"f01efdf6fe3b2bb387d3094aa701203f.jpg","alt":"","caption":"","primary":true},"b11581adadd1848acb2898e7a284afc1":{"filename":"b11581adadd1848acb2898e7a284afc1.png","alt":"","caption":""},"2cfee6d3c334696833b1cfe13910fcf1":{"filename":"2cfee6d3c334696833b1cfe13910fcf1.png","alt":"","caption":""}}
如您所见,那里有3张图像,我需要的是在foreach循环中仅回显“主”值为:true的图像...
编辑:
<?php
$query = $this->db->query("SELECT * FROM offers_products WHERE offer_large LIMIT 5;");
?>
<?php foreach ($query->result() as $row): ?>
<li><a href="/<?=$row->slug?>"><?=$row->id?></a></li>
<li><?=$row->name?></li>
<li><!-- THIS IS THE IMAGES TABLE VALUE --> <?=$row->images?> <!-- --></li>
<li><?=$row->description?></li>
<?php endforeach; ?>