2017-10-12 10 views
0

"product1、$ 1,35; product2、$ 1,50; product3のようなテーブルの中に、 $ 5,50"配列の複数の文字列を隣り合わせに設定する方法

しかし、私はそれらを印刷するとき、今、彼らは私の画面上で、このように取得:ここ

enter image description here

は私のJSONデコードされた配列のvar_dumpです:

array(4) { ["product_id"]=> int(1) ["product_name"]=> string(12) "Broodje Kaas" ["product_quantity"]=> int(1) ["product_price"]=> int(205) } array(4) { ["product_id"]=> int(2) ["product_name"]=> string(11) "Broodje ham" ["product_quantity"]=> int(3) ["product_price"]=> int(107) } array(4) { ["product_id"]=> int(1) ["product_name"]=> string(10) "Broodje ei" ["product_quanity"]=> int(1) ["product_price"]=> int(205) } array(4) { ["product_id"]=> int(2) ["product_name"]=> string(11) "Broodje kip" ["product_quanity"]=> int(3) ["product_price"]=> int(107) } array(4) { ["product_id"]=> int(1) ["product_name"]=> string(12) "Broodje Kaas" ["product_quanity"]=> int(1) ["product_price"]=> int(205) } array(4) { ["product_id"]=> int(2) ["product_name"]=> string(11) "Broodje ham" ["product_quanity"]=> int(3) ["product_price"]=> int(107) } 

と私の$ productidsのvar_dump:ここ

array ([0] => Array ([id] => 1 [order_items] => [{"product_id":1,"product_name":"Broodje Kaas","product_quantity":1,"product_price":205},{"product_id":2,"product_name":"Broodje ham","product_quantity":3,"product_price":107}] [order_price] => 2,50 [order_date] => 2017-10-12 18:08:43 [order_state] => 1 [order_is_paid] => 1) [1] => Array ([id] => 2 [order_items] => [{"product_id":1,"product_name":"Broodje ei","product_quanity":1,"product_price":205},{"product_id":2,"product_name":"Broodje kip","product_quanity":3,"product_price":107}] [order_price] => 3,00 [order_date] => 2017-10-12 18:04:38 [order_state] => 0 [order_is_paid] => 0) [2] => Array ([id] => 3 [order_items] => [{"product_id":1,"product_name":"Broodje Kaas","product_quanity":1,"product_price":205},{"product_id":2,"product_name":"Broodje ham","product_quanity":3,"product_price":107}] [order_price] => 5,60 [order_date] => 2017-10-12 14:40:51 [order_state] => 2 [order_is_paid] => 1)) Array ([0] => Array ([id] => 1 [order_items] => [{"product_id":1,"product_name":"Broodje Kaas","product_quantity":1,"product_price":205},{"product_id":2,"product_name":"Broodje ham","product_quantity":3,"product_price":107}] [order_price] => 2,50 [order_date] => 2017-10-12 18:08:43 [order_state] => 1 [order_is_paid] => 1) [1] => Array ([id] => 2 [order_items] => [{"product_id":1,"product_name":"Broodje ei","product_quanity":1,"product_price":205},{"product_id":2,"product_name":"Broodje kip","product_quanity":3,"product_price":107}] [order_price] => 3,00 [order_date] => 2017-10-12 18:04:38 [order_state] => 0 [order_is_paid] => 0) [2] => Array ([id] => 3 [order_items] => [{"product_id":1,"product_name":"Broodje Kaas","product_quanity":1,"product_price":205},{"product_id":2,"product_name":"Broodje ham","product_quanity":3,"product_price":107}] [order_price] => 5,60 [order_date] => 2017-10-12 14:40:51 [order_state] => 2 [order_is_paid] => 1)) Array ([0] => Array ([id] => 1 [order_items] => [{"product_id":1,"product_name":"Broodje Kaas","product_quantity":1,"product_price":205},{"product_id":2,"product_name":"Broodje ham","product_quantity":3,"product_price":107}] [order_price] => 2,50 [order_date] => 2017-10-12 18:08:43 [order_state] => 1 [order_is_paid] => 1) [1] => Array ([id] => 2 [order_items] => [{"product_id":1,"product_name":"Broodje ei","product_quanity":1,"product_price":205},{"product_id":2,"product_name":"Broodje kip","product_quanity":3,"product_price":107}] [order_price] => 3,00 [order_date] => 2017-10-12 18:04:38 [order_state] => 0 [order_is_paid] => 0) [2] => Array ([id] => 3 [order_items] => [{"product_id":1,"product_name":"Broodje Kaas","product_quanity":1,"product_price":205},{"product_id":2,"product_name":"Broodje ham","product_quanity":3,"product_price":107}] [order_price] => 5,60 [order_date] => 2017-10-12 14:40:51 [order_state] => 2 [order_is_paid] => 1)) 

とは私のコードである

<table class="table table-striped"> 
<?php $output = "<tr><th># </th><th>Producten </th><th>Prijs </th></tr>";?> 
<tbody> 
<tr> 

UW bestelde producten

<?php foreach ($productsids as $value) { 

    $output .= "<tr>"; 
    $orderitems = json_decode($value['order_items'], true); 
    $output .= "<td>" .$value['id']. "</td>"; 

    foreach ($orderitems as $item) { 
     var_dump($item); 

     $output .= "<td>" .$item['product_name']. "</td>"; 
     $output .= "<td>" .$item['product_price']. "</td>"; 

     //$output .= "<td>" .$item['product_quantity']. "</td>"; 

    } 
    $output .= "</tr>"; 

} 
echo $output; 
?> 

</tr> 
</tbody> 

+0

あなたはproductsidsますprint_r($ productsids)$を印刷することができますか? –

+0

@RavinderReddyこれが表示されます:https://gyazo.com/74dcf79df527d5730f43df55be2bf99b –

+0

イメージは動作しません。コードを貼り付けます。 –

答えて

1

あなたは1つの製品ごとを入れている場合行、あなたはサブ製品のforeachの内側にtrを処理し、それらをスパンする必要があります最初のセルに行番号が付いています。このような

何か:

foreach ($productsids as $value) { 
    $orderitems = json_decode($value['order_items'], true); 
    $output .= "<tr>"; 
    $output .= '<td rowspan="'. count($orderitems) .'">' . $value['id'] . "</td>"; 
    foreach ($orderitems as $r => $item) { 
     if ($r!=0) { $output .= "</tr><tr>"; } 
     $output .= "<td>" . $item['product_name'] . "</td>"; 
     $output .= "<td>" . $item['product_price'] . "</td>"; 
    } 
    $output .= "</tr>"; 
} 
+1

私のヒーローは働いてくれてありがとう! –

+0

彼の答えを受けて礼儀を示しています。 –

+0

まだ小切手と残高を追加する必要があります。たとえば、注文に商品がない場合(rowspan = 0はhtmlで乱雑です)、何が起こるかを処理します。 – IncredibleHat

関連する問題