如何使用 json php 和 mysql 显示数据库中的数据。我一直在尝试,但我未能获胜,但如果我不包含 jquery,它会以一种有趣的方式显示。我将不胜感激任何帮助。贝娄是我到目前为止所尝试的。
<?php
require_once('dbbox.php');
?>
<?php
$sql = "SELECT * FROM
m1debtors INNER JOIN
m1dtrans
ON m1debtors.name = m1dtrans.user";
$result = mysql_query($sql, $con) or die(mysql_error($con));
while ($row = mysql_fetch_array($result)){
$accnum = $row['accnum'];
$name = $row['name'];
$addr1 = $row['addr1'];
}
// The JSON standard MIME header.
header('Content-type: application/json');
$array = array('Name'=>$name, 'user'=>$user);
echo json_encode($array);
?>
Here is the html page to display data
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$.getJSON("view.php",{$name});
});
</script>