Php 如何显示mysql Json数据

Php 如何显示mysql Json数据,php,mysql,json,codeigniter,Php,Mysql,Json,Codeigniter,我在数据库中有一个表,请致电购买。其中,我插入了少量数据作为JOSN格式。在该json格式中,存储了多个数据。exp-“产品”有2个数据 我使用了json\u decode()函数,我得到了这个- Array ( [0] => stdClass Object ( [products] => Array ( [0] => Asulak Silver 7

我在数据库中有一个表,请致电购买。其中,我插入了少量数据作为JOSN格式。在该json格式中,存储了多个数据。exp-“产品”有2个数据

我使用了
json\u decode()
函数,我得到了这个-

Array
(
    [0] => stdClass Object
        (
            [products] => Array
                (
                    [0] => Asulak Silver 7
                    [1] => Print Gum MAP NEW
                )

        )

    [1] => stdClass Object
        (
            [qnt] => Array
                (
                    [0] => 2
                    [1] => 1
                )

        )

    [2] => stdClass Object
        (
            [unit_price] => Array
                (
                    [0] => 1500
                    [1] => 600
                )

        )

    [3] => stdClass Object
        (
            [pack_size] => Array
                (
                    [0] => 60
                    [1] => 60
                )

        )

    [4] => stdClass Object
        (
            [unit_pack] => Array
                (
                    [0] => 2
                    [1] => 1
                )

        )

    [5] => stdClass Object
        (
            [packing] => Array
                (
                    [0] => Dram
                    [1] => Jar
                )

        )

    [6] => stdClass Object
        (
            [total_kg] => Array
                (
                    [0] => 120
                    [1] => 60
                )

        )

    [7] => stdClass Object
        (
            [total_price] => Array
                (
                    [0] => 3000
                    [1] => 600
                )

        )

)
但我不知道如何在我的视图表中显示如下-

我是Codeigniter的新手。请帮我提前谢谢你

我用过这个密码

$json = array(  array('products' => $products), 
                array('qnt' => $qnt), 
                array('unit_price' => $unit_price), 
                array('pack_size' => $pack_size), 
                array('unit_pack' => $unit_pack), 
                array('packing' => $packing), 
                array('total_kg' => $total_kg), 
                array('total_price' => $total_price) 
            ); 
$json_type = json_encode($json); //Sending arrays into json

用于阵列重新排列的用户代码:

$array = json_decode( $json, true );
$data=array();
foreach($array as $value){
    foreach($value as $key=>$value){
    }
    $data[$key]=$value;
}
要查看,请使用以下代码:

<table border="1">
<tr>
<td>Product Name</td>
<td>Quantity</td>
<td>unit_price</td>
<td>pack_size</td>
<td>unit_pack</td>
<td>packing</td>
<td>total_kg</td>
<td>total_price</td>
</tr>
<?php
foreach($data['products'] as $k=>$v){?>
    <tr>
    <td><?php echo $v; ?></td>
    <td><?php echo $data['qnt'][$k]; ?></td>
    <td><?php echo $data['unit_price'][$k]; ?></td>
    <td><?php echo $data['pack_size'][$k]; ?></td>
    <td><?php echo $data['unit_pack'][$k]; ?></td>
    <td><?php echo $data['packing'][$k]; ?></td>
    <td><?php echo $data['total_kg'][$k]; ?></td>
    <td><?php echo $data['total_price'][$k]; ?></td>
    </tr>
<?php }
?>
</table>

品名
量
单价
包装尺寸
单位包装
包装
总重量(千克)
总价

看起来像是一开始就不应该在JSON中的数据我使用这个代码-$JSON=数组(数组($products'=>$products),数组($qnt'=>$qnt),数组($unit\U price'=>$unit\U price),数组($pack\U size'=>$pack\U size),数组($unit\U pack'=>$unit\U pack),数组('packing'=>$packing),数组('total_kg'=>$total_kg),数组('total_price'=>$total_price));$json_type=json_encode($json);//将数组发送到jsonWell您有一个对象数组。您所需要做的就是编写一个循环。那么问题出在哪里?没有人可以阅读注释中的代码。编辑您的问题以添加更多信息下次谢谢您的帮助(y)@MarufAhmed Welcome
<table border="1">
<tr>
<td>Product Name</td>
<td>Quantity</td>
<td>unit_price</td>
<td>pack_size</td>
<td>unit_pack</td>
<td>packing</td>
<td>total_kg</td>
<td>total_price</td>
</tr>
<?php
foreach($data['products'] as $k=>$v){?>
    <tr>
    <td><?php echo $v; ?></td>
    <td><?php echo $data['qnt'][$k]; ?></td>
    <td><?php echo $data['unit_price'][$k]; ?></td>
    <td><?php echo $data['pack_size'][$k]; ?></td>
    <td><?php echo $data['unit_pack'][$k]; ?></td>
    <td><?php echo $data['packing'][$k]; ?></td>
    <td><?php echo $data['total_kg'][$k]; ?></td>
    <td><?php echo $data['total_price'][$k]; ?></td>
    </tr>
<?php }
?>
</table>