select.php
<?php $con = mysql_connect("localhost","Thh","920920thh"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM Persons WHERE FirstName = " . "'" . $_POST[firstname] . "'"); $arr=array(); while($row = mysql_fetch_array($result,MYSQL_ASSOC)) { //echo $row['FirstName'] . " " . $row['LastName'] . " " . $row['Age']; //echo "<br />"; $arr[]=$row; } echo json_encode($arr); mysql_close($con); ?>
echo出的数据格式如下
[{"id":"43","firstName":"u8c2d","lastName":"u72d7u72d7","age":"18"},{"id":"44","firstName":"u8c2d","lastName":"u55e8","age":"66"}]