I have json html table in php, now i can't get it work that the output in the table will be near each other.
I am already few days busy with this, hope some one can help me.
<?php foreach($data2 as $row): ?>
<tr>
<td><?=$row['model'];?></td>
<td><?=$row['model2'];?></td>
</tr>
<?php endforeach;?>
My json output:
My Answer:
It sounds like you are trying to output the rows of your HTML table in a specific order using PHP. One way to achieve this is by using a foreach loop to iterate over your data and output the rows in the desired order.
Here is an example of how you can achieve this:
php
// Your JSON data
$jsonData = '{
"data": [
{"name": "John", "age": 30},
{"name": "Jane", "age": 25},
{"name": "Bob", "age": 35}
]
}';
// Decode the JSON data
$data = json_decode($jsonData, true);
// Output the table
echo '';
foreach ($data['data'] as $row) {
echo '';
echo '' . $row['name'] . ' ';
echo '' . $row['age'] . ' ';
echo ' ';
}
echo '
';
?>
In this example, we first decode the JSON data using `json_decode()` and then iterate over the `data` array using a foreach loop. Inside the loop, we output each row of the table with the desired order of columns.
Make sure to adjust the code according to your specific JSON data structure and table layout. Let me know if you need further assistance!
Rate this post
4 of 5 based on 8027 votesComments