[英]How to fix php foreach in CodeIgniter
A PHP Error was encountered Severity: Warning 遇到PHP错误严重性:警告
Message: Invalid argument supplied for foreach() 消息:为foreach()提供了无效的参数
Filename: admin/v_pembelian.php 文件名:admin / v_pembelian.php
Line Number: 80 行号:80
<tbody>
<?php $i = 1; ?>
<?php foreach ($this->cart->contents() as $items){ ?>
<?php echo form_hidden($i.'[rowid]', $items['rowid']); ?>
<tr>
<td><?=$items['id'];?></td>
<td><?=$items['name'];?></td>
<td style="text-align:center;"><?=$items['satuan'];?></td>
<td style="text-align:right;"><?php echo number_format($items['price']);?></td>
<td style="text-align:right;"><?php echo number_format($items['harga']);?></td>
<td style="text-align:center;"><?php echo number_format($items['qty']);?></td>
<td style="text-align:right;"><?php echo number_format($items['subtotal']);?></td>
<td style="text-align:center;"><a href="<?php echo base_url().'admin/pembelian/remove/'.$items['rowid'];?>" class="btn btn-warning btn-xs"><span class="fa fa-close"></span> Batal</a></td>
</tr>
<?php $i++; ?>
<?php } ?>
</tbody>
I want to display data on items that have been inserted 我想显示有关已插入项目的数据
Although I am not positive of the structure of $this->cart->contents()
, casting this object to an array like so: (array)$this->cart->contents()
will probably give the results you are expecting; 尽管我对$this->cart->contents()
的结构不是很$this->cart->contents()
,但将此对象转换为如下所示的数组: (array)$this->cart->contents()
可能会给出您期望的结果;
<tbody>
<?php $i = 1; ?>
<?php foreach ((array)$this->cart->contents() as $items){ ?>
<?php echo form_hidden($i.'[rowid]', $items['rowid']); ?>
<tr>
<td>
<?=$items['id'];?></td>
<td>
<?=$items['name'];?></td>
<td style="text-align:center;">
<?=$items['satuan'];?></td>
<td style="text-align:right;">
<?php echo number_format($items['price']);?></td>
<td style="text-align:right;">
<?php echo number_format($items['harga']);?></td>
<td style="text-align:center;">
<?php echo number_format($items['qty']);?></td>
<td style="text-align:right;">
<?php echo number_format($items['subtotal']);?></td>
<td style="text-align:center;">
<a href="
<?php echo base_url().'admin/pembelian/remove/'.$items['rowid'];?>" class="btn btn-warning btn-xs"><span class="fa fa-close"></span> Batal</a>
</td>
</tr>
<?php $i++; ?>
<?php } ?>
</tbody>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.