[eluser]rochellecanale[/eluser]
hello guys i have a problem about displaying array.
Here's my sample function in my controller:
Code:
<?php
foreach($product->result_array() as $row){
echo "<tr>";
echo "<td>{$row['product_name']}</td>";
echo "<td>{$row['date_of_sales']}</td>";
echo "<td>{$row['qty_purchased']}</td>";
echo "<td>{$row['subtotal']}</td>";
echo "</tr>";
$product_id = $row['product_id']; //id
$product_name = $row['product_name'];
$date_of_sales = $row['date_of_sales'];
$qty_purchased = $row['qty_purchased'];
$subtotal = $row['subtotal'];
$transact[$product_id]['id'] = $product_id;
$transact[$product_id]['product_name'] = $product_name;
$transact[$product_id]['date_of_sales'] = $date_of_sales;
$transact[$product_id]['qty_purchased'] = $qty_purchased;
$transact[$product_id]['subtotal'] = $subtotal;
echo "<pre>";
print_r($transact);
}
My problem is my array display only the last value per id. For example let's say we have the following result.
Code:
Product ID Product Name Qty Total
1 product a 1 5.00
1 product a 2 10.00
2 product b 1 5.00
3 product c 1 8.00
3 product c 2 16.00
4 product d 1 5.00
5 product e 1 5.00
My output when i try to get the value of array is like this:
Code:
Product ID Product Name Qty Total
1 product a 2 10.00 //display last value of id 1
2 product b 1 5.00
3 product c 2 16.00 //display last value of id 3
4 product d 1 5.00
5 product e 1 5.00
The first id is not showing. What is the problem in my code? How can i display all the values?