0

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 .

3
  • And what's the difference in output from what you expect? Commented Aug 7, 2014 at 7:29
  • it not show the format table that I want . Commented Aug 7, 2014 at 7:34
  • And what format does it show? Can you add that to your question? Commented Aug 7, 2014 at 7:43

1 Answer 1

1

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>';
}
Sign up to request clarification or add additional context in comments.

1 Comment

can I know ,what is the function for $rem ? is it count for row?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.