JSON编码以创建表

How can I eventually put the following code into a table or viewable format.

$query = 
  "SELECT title, descr FROM details";

$result = mysqli_query($connection,$query);

$details = array();
while ($row = mysqli_fetch_assoc($result)) {
  array_push($details, $row);
}

echo json_encode($details);

No need to json encode the result, however with making tables I like to make a json template file to dictate how the table should be constructed so that I can make changes easily.

// this would normally be located elsewhere.
$templateJson = '"columns": {

    "title":{
        "title": "Title",
        "class": "title"
    },
    "descr":{
        "title": "Description",
        "class": "descr"
    }
}';

$template = json_decode($templateJson);

if(is_array($details))
{
    $markup = "<table><thead><tr>";

    foreach($template["columns"] as $col=>$format)
    {
        $markup .= '<th class="'.$format['class'].'">';
        $markup .= $format['title'];
        $markup .= '</th>';
    }

    $markup .= "</tr></thead><tbody>";  

    foreach($details as $i=>$row)
    {
        $markup .= '<tr>';  
        foreach($template as $col=>$format)
        {
            $markup .= '<td>'.$row[$col].'</td>';
        }
        $markup .= '</tr>';
    }

    $markup .= "</tbody></table>";  
}

echo $markup;

I tend to do way more loops than I probably should though, there may be a more optimal way but this will give you valid table markup.