0

I have json file like this

[{
    "Shop_name": "916",
    "Shop_id": "916TCR",
    "Address":"cdsasffafa"
    "numbers": "4",
    "mob_no": "9447722856"
}, {
    "Shop_name": "Chicking",
    "Shop_id": "CKGTCR",
    "Address":"afagagg",
    "numbers": "8",
    "mob_no": "6767564532"
}]

i want to see this as HTML Table with row head as Shop_name,Shop_id,Address and Data in next row.

i tried decoding it and display as table (How can i parse json into a html table using PHP?). but Json File format is diffrent here. Also like to know if Json File gets bigger with [0],[1],[2]....

4
  • I dont think that is valid JSON with those odd double quotes Commented Feb 1, 2016 at 15:55
  • Corrected JSON !@RiggsFolly Commented Feb 1, 2016 at 15:59
  • So now the caracter set is fixed, it just a case of doing some coding Commented Feb 1, 2016 at 16:03
  • Please show the code actual that you have actually used to try to get it to work Commented Feb 1, 2016 at 16:30

1 Answer 1

3

You should parse your json data to php object than you should iterate your data like below;

$myData = <<<JSON

[
{"Shop_name":"minh",
  "Shop_id":"916TCR",
  "Address":"cdsasffafa",
  "numbers":"4",
  "mob_no":"9447722856"
},
{"Shop_name":"Chig",
 "Shop_id":"CKGTCR",
 "Address":"afagagg",
 "numbers":"8",
 "mob_no":"6767564532"
}
]

JSON;

$myObject = json_decode($myData);

?>
<table>
<tr>
    <td>Shop Name</td>
    <td>Shop ID</td>
    <td>Address</td>
    <td>Numbers</td>
    <td>Mob No</td>
</tr>
<?PHP
foreach($myObject as $key=>$item)
{
    ?>
    <tr>
        <td><?PHP echo $item->Shop_name; ?></td>
        <td><?PHP echo $item->Shop_id; ?></td>
        <td><?PHP echo $item->Address; ?></td>
        <td><?PHP echo $item->numbers; ?></td>
        <td><?PHP echo $item->mob_no; ?></td>
    </tr>
    <?PHP
}
?>
</table>

A working example is here: http://ideone.com/IqZLMs

PS: You should fix this ” quote to "

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.