我有以下代码:
<?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 也没有设置为值。我错过了什么?