通过设置列数和行数在php中创建json表

通过设置列数和行数在php中创建json表

问题描述:

I have a Json result like this :

Array(5) (
     [Street] => Street_name 
     [status] => Best_Shop 
     [Shop] => Array (30) ( 
                   [0] => Array(9) ( 
                        [Name] => Bakery_Shop 
                        [Owner] => John
                        [Type] => 0 
                        [Food] => Cake 
                        [Drink] => Coffee 
                        [Best_Customer] => All
                        [a] => Good 
                        [b] => Normal
                        [c] => Bad  
                   [1] => Array(9) ( 
                        [Name] => Junk_Foodshop 
                        [Owner] => Mike
                        [Type] => 0 
                        [Food] => Burger 
                        [Drink] => Coke 
                        [Best_Customer] => All
                        [a] => Good 
                        [b] => Normal
                        [c] => Bad ) 
                   [2] =>....
                   [3] =>....
             )
    [Rate] => Average 
    [Signature] => Boss )

And i am trying to create a shop table with rows and column format 10 x 3 displaying only the owner name like this :

+-----------+---------+-----------+---------+-----------+---------+---------+
|    John   |  Mike   |   owner_3 |  owner_5    owner_6   .....    owner_10 |
+-----------+---------+-----------+---------+-----------+---------+---------+
| owner_11  | ................................................... |owner_20
+-----------+---------+-----------+---------+-----------+---------+---------+
| owner_21  |  .................................................. |owner_30 |
+-----------+---------+-----------+---------+-----------+---------+---------+

I currently have this code written up and although i am getting the data its not quite working the way i want it to be.

$ShopTable.='<table style="width:990px;" id="" border="1">';
$ShopTable.='<thead>';

$ShopJson = getShop();
$ShopChan = $ShopJson['Shop'];
$ShopTable.='<tr>';
if (count($ShopChan ) > 0) {
    for ($i = 0; $i < count($ShopChan); $i++) {
        $ShopChanRecord = $ShopChan[$i];
            $ShopTable.='<td>' . $ShopChanRecord['Owner'] . '</td>';

    }
}
$ShopTable.='</tr>';
$ShopTable.='</tbody>';
$ShopTable.='</table>';
echo $ShopTable;

Does anyone can see if any problem about my code? Any help would be greatly appreciated.Thank you .

try this

$ShopChan = $ShopJson['Shop'];

if(count($ShopChan ) > 0) 
{
    $ShopTable.='<table style="width:990px;" id="" border="1">';
    for ($i = 0; $i < count($ShopChan); $i++) {
        $rem = ($i+1)%10;
        if($rem==1)
        {
            $ShopTable.='<tr>'; 
        }
            $ShopChanRecord = $ShopChan[$i];
            $ShopTable.='<td>' . $ShopChanRecord['Owner'] . '</td>';

        if(($rem==0)
        {
            $ShopTable.='</tr>';    
        }   
    }

    if($rem!=0)
    {
        for($j=$rem; $j>=0; $j--)
        {
            $ShopTable.='<td>&nbsp;</td>';
        }
        $ShopTable.= '</tr>';
    }

    $ShopTable.='</table>';
}