Drodzy forumowicze, mam pewien problem i byłbym rad gdyby ktoś pomógł mi go rozwiązać. Do sedna.
A więc tworzę sklep internetowy i mam problem z wyświetlaniem zamówień z bazy danych.
User_id czy User_Email się wyświetla natomiast nie wiem jak wyświetlić dane zawarte w tablicach (id, name, price, size itp) znajujące się w ["items"]
var_dump($order):
object(stdClass)#24 (6) {
["id"]=>
string(2) "10"
["user_id"]=>
string(2) "17"
["user_email"]=>
string(26) "xxxxxxxxx@gmail.com"
["items"]=> // Tu zaczyna się problem i nie wiem jak wyświetlić poniższe pola
array(2) {
["14S"]=>
array(7) {
["id"]=>
string(2) "14"
["name"]=>
string(12) "Przedmiot 1" // Jak wyświetlić np tą nazwę przedmiotu
["price"]=>
string(2) "22"
["size"]=>
string(1) "S"
["qty"]=>
string(1) "1"
["thumb"]=>
string(37) "thumb.jpg"
["total_item_price"]=>
int(22)
}
["13S"]=>
array(7) {
["id"]=>
string(2) "13"
["name"]=>
string(16) "Przedmiot 2"
["price"]=>
string(2) "67"
["size"]=>
string(1) "S"
["qty"]=>
string(1) "5"
["thumb"]=>
string(37) "thumb.jpg"
["total_item_price"]=>
int(335)
}
}
["total_price"]=>
string(3) "357"
["payment_method"]=>
string(10) "transferuj"
}
Controller dodający produkt do bazy:
$item = json_encode($this->session->userdata( 'cart' ));
if( !empty($_POST) )
{
// walidacja formularza
if ( $this->form_validation->run( 'payment-type' ) == TRUE)
{
$data = array(
'user_id' => $user_id,
'user_email'=> $user->email,
'items' => $item,
'total_price' => $pricetopay,
'payment_method' => $this->input->post('platnosc'),
);
$this->crud_m->create('orders', $data);
}
Controller pobierający z bazy:
$orders = $this->crud_m->get('orders');
foreach ($orders as $order )
{
$order->items = json_decode($order->items, true);
}
$data['orders'] = $orders;
Widok: (To poniżej akurat się wyświetla)
<?php foreach ($orders as $order): ?>
<tr>
<td><?php echo $order->id; ?></td>
<td><?php echo $order->user_id; ?></td>
<td><?php echo $order->user_email; ?></td>
</tr>
<?php endforeach; ?>