我有以下代碼:如何分析和mysql_fetch_row成JSON對象
<?php
include 'db.php';
$con = mysql_connect($host,$user,$pass);
$dbs = mysql_select_db($databaseName, $con);
$tableName = "tbl_title";
$result = mysql_query("SELECT id, fld_title FROM $tableName");
$data = array();
while ($row = mysql_fetch_row($result))
{
//$data[] = $row;
//$data['item'][] = $row;
//$data['item'][] = $row['id'].value;
$id = $row['id'];
$fld_title = $row['fld_title'];
$data = array("id" => $id, "fld_title" => $fld_title);
//echo $row['id'] . " " . $row['fld_title'];
//echo '<option value="'.$row->id.'">'.$row->fld_title.'</option>';
}
echo json_encode($data);
// echo $row[0] . " " . $row[1];
?>
我想但是返回的結果格式化的方式,即使我得到的查詢,$ ID和$結果fld_title不會被設置爲一個值。我錯過了什麼?
啊哈!這正是我錯過的...... – NinjaCat