如何使用json php和mysql顯示數據庫中的數據。 我一直在嘗試,但我沒有贏,但如果我不包括jquery它顯示,但在一個有趣的方式。 我會很感激的任何幫助。 貝婁是我到目前爲止嘗試過的。如何使用json顯示來自mysql的數據
<?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>
[**請不要使用'mysql_ *'功能在新代碼**] (http://bit.ly/phpmsql)。他們不再被維護[並被正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 – vanneto
嘗試這些鏈接http://www.9lessons.info/2009/10/json-jquery-ajax-php.html或http://stackoverflow.com/questions/327231/best-way-to-display-data-通過-JSON-使用,jquery的 –
好,謝謝,我會改變 – Musa