我希望在給每行顯示唯一ID的同時在我的視圖中顯示數據庫查詢的結果。顯示數據庫數組行,同時每行自動增加id
我的模式是:
function get_load_lines($ordernumber)
{
$this->db->select('product,pricepercube,qty,linecost,linediscount,cubicvolume,bundles,treated,autospread');
$this->db->from('Customer_Order_Lines');
$this->db->where('CustomerOrderID',$ordernumber);
$q = $this->db->get();
if($q->num_rows() > 0)
{
return $q->row_array();
}
}
我的控制器:
function edit_order_lines()
{
$data = array(
'ordernumber' =>$this->input->post('ordernumber'),
'customer' =>$this->input->post('customer'),
'loadlines' => $this->sales_model->get_load_lines($this->input->post('ordernumber'))
);
$this->load->view('sales/edit_order_lines',$data);
}
如前所述我想在視圖中顯示的每一列中。
所以我在我看來,使用此代碼:
<table>
<?php
$i=1;
foreach ($loadlines as $row)
{
echo "<tr>";
echo "<td>".$i."</td>";
echo "<td>".$row['product']."</td>";
echo "<td>".$row['pricepercube']."</td>";
echo "<td>".$row['qty']."</td>";
echo "</tr>";
$i++;
}
?>
</table>
這不會有預期的結果。每個數組條目的增量爲$i
,而不是每個數組行。
有關顯示此數據的最佳方式的任何建議?
所以,如果3行以下要求:
冠軍,完美的作品。欣賞你的時間和知識! – Smudger 2013-05-13 13:22:00
沒問題。很高興我能幫上忙! – jleft 2013-05-13 13:23:49