<table border=1>
<tr>
<td>pathologie</td>
<td>mois</td>
<td>nb_cas</td>
<td>RegionID</td>
</tr>
<?php
$json = '{"table":[{"pathologie":"Sida","mois":"1","nb_cas":"0.0000","RegionID":"1"},{"pathologie":"H\u00e9pathite A","mois":"1","nb_cas":"0.0036","RegionID":"1"},{"pathologie":"Diphterie","mois":"8","nb_cas":"0.0067","RegionID":"1"},{"pathologie":"Tuberculose","mois":"1","nb_cas":"0.0079","RegionID":"1"},{"pathologie":"Cholera","mois":"1","nb_cas":"0.0356","RegionID":"1"},{"pathologie":"Paludisme","mois":"1","nb_cas":"0.0611","RegionID":"1"}]}';//get json here as you want
$data = json_decode($json);
foreach( $data->{'table'} as $val){
$pathologie = $val->pathologie;
$mois = $val->mois;
$nb_cas = $val->nb_cas;
$RegionID = $val->RegionID;
echo "<tr><td>$pathologie </td>";
echo "<td>$mois </td>";
echo "<td>$nb_cas </td>";
echo "<td>$RegionID </td></tr>";
}
echo "</table>";
?>
并使用jQuery:
$.getJSON("http://url.com/json.php&callback=?", function(data){
var tablecontents = "";
tablecontents ='<table>';
$.each(data, function (index, value) {
tablecontents += "<tr class='tr'>";
tablecontents += "<td>"+value["pathologie"]+"</td>";
tablecontents += "<td>"+value["mois"].toString()+"</td>";
tablecontents += "<td>"+value["nb_cas"].toString()+"</td>";
tablecontents += "<td>"+value["RegionID"].toString()+"</td>";
tablecontents += "</tr>";
}
});
document.getElementById("textTable").innerHTML = tablecontents;
});
}
<div id=textTable style="color:white;"></div>
希望你有一个想法..如何使用来自 json 的 jquery 打印表格