// 設置返回json格式數據
header('content-type:application/json;charset=utf8');
//連接數據庫
$link = mysql_connect("localhost", "root", "root") or die("Unable to connect to the MySQL!");
mysql_query("SET NAMES 'UTF8'");
mysql_select_db("jilinwula", $link) or die("Unable to connect to the MySQL!");
// 獲取分頁參數
$page = 0 ;
$pageSize = 3;
if(!is_null($_GET["page"])) {
$page = $_GET["page"];
}
if(!is_null($_GET["pageSize"])) {
$pageSize = $_GET["pageSize"];
}
// 查詢數據到數組中
$result = mysql_query("select username,password from userinfo limit " . $page . ", ". $pageSize ."");
$results = array();
while ($row = mysql_fetch_assoc($result)) {
$results[] = $row;
}
// 將數組轉成json格式
echo json_encode($results);
// 關閉連接
mysql_free_result($result);
mysql_close($link);