hi i have an php code which is read an json field value and displayed in the table format my code is working fine but the data is not arranged properly how to fix this one can anyone help me on this
$post_id = get_the_ID();
$dataproducts = get_field( “data_product”, $post_id);
$data = json_decode($dataproducts);
$table = '
<table class="company-sub-table">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Uses Data Product</th>
<th>Customer Type</th>
</tr>
</thead>
<tbody>
';
foreach ($data as $dataproducts_var) {
foreach ($dataproducts_var->name as $name_of_dp)
{
echo "<script>console.log('Console: " . $name_of_dp . "' );</script>";
$name_dp = $name_of_dp;
echo "<script>console.log('Console: " . $name_dp . "' );</script>";
$table .= '
<tr>
<td>' . $name_dp . '</td>
<td></td>
<td></td>
<td></td>
</tr>
';
}
foreach ($dataproducts_var->description as $description)
{
$description_to_print = $description;
$table .= '
<tr>
<td></td>
<td>' . $description_to_print . '</td>
<td></td>
<td></td>
</tr>
';
}
foreach ($dataproducts_var->uses_data_product as $uses_dp)
{
$uses_dp_to_display = $uses_dp;
$table .= '
<tr>
<td></td>
<td></td>
<td>' . $uses_dp_to_display . '</td>
<td></td>
</tr>
';
}
foreach ($dataproducts_var->customer_type as $c_type)
{
$c_type_to_display = $c_type;
$table .= '
<tr>
<td></td>
<td></td>
<td></td>
<td>' . $c_type_to_display . '</td>
</tr>
';
}
}
$table .= '
</tbody>
</table>
';
echo $table;
this is the json field value———- [{“name”:[“JDLink “],”description”:[“Solution that fits any make/model of equipment, including older John Deere and non-John Deere equipment. Places essential machine information such as location, machine hours, and alerts at the usersu2019 fingertips, leaving them in complete control to increase machine productivity.”],”uses_data_product”:[“GPS Data, Equipment/Maintanence Data”],”customer_type”:[“Vehicle Fleet Operators”]},{“name”:[“Granular Insights”],”description”:[“John Deere’s telematics system supports operational improvements by providing information such as field ops data like hours, acres and quantities of inputs applied, and crops harvested. Premium services are sold at 6$ per Acre. “],”uses_data_product”:[“Farm Yeild Data”],”customer_type”:[“Farmers”]}]