【发布时间】:2012-10-09 17:46:54
【问题描述】:
型号
$data = array();
$session_id = $this->session->userdata('id');
$q = $this->db->get_where('cust_orders', array('cust_id' => $id));
foreach ($q->result() as $row)
{
$data['id'] = $row->cust_id;
$data['orders'] = $row->cart;
}
return $data;
控制器
将data 传递给视图
查看
<?php foreach($_orders as $key => $item) : ?>
<tr>
<td>
<?php
$price = $item['price']; #change this to order status
switch ($price)
{
case (64); $UPSTrack = '1Z12345E1512345676'; #Shipped add tracking number
echo 'Shipped <br> <a href="http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums='.$UPSTrack.'">Track My Order</a>';
break;
case (88);
echo 'Shipped';
break;
default;
echo 'Processing';
break;
}
?>
</td>
<td>
<?php foreach ($item['options'] as $option => $value)
{
echo '<span class="option">'.$option . ': </span> <span class="options">' . $value . '</span>';
}
?>
</td>
<td><?php echo $item['id']; ?></td>
<td><?php echo $item['qty']; ?></td>
<td><?php echo number_format($item['price'],2); ?></td>
</tr>
<?php endforeach; ?>
选项是一个数组
包含一个foreach,它循环遍历变量$data['orders'] = $row->cart;中包含的array
在数据库中,我通过cust_id 查找cust_orders 表一个客户可能有多个1 行,这意味着多个订单。
问题是我只循环最后一行。我需要遍历cust_id = 到$session_id 的所有行。
我觉得问题出在我的MODEL,因为如果我将$data['id'] = $row->cust_id; 更改为echo $row->cust_id;' I am able to see all of the rows which match the customers id, but it breaks myforeach` 代码。
如何正确分配 MODEL 查询中返回的 values 以便显示所有 cust_orders == 到 $session_id?
【问题讨论】:
标签: php codeigniter mysqli