2015년 4월 24일 금요일

PHP : JSON (Multi-Row/JSONArray) Sample Code

PHP :  JSON (Multi-Row/JSONArray) Sample Code

<?
$_zb_url = "http://$_SERVER[HTTP_HOST]/admin/";
$_zb_path =$_SERVER["DOCUMENT_ROOT"]."/admin/";
REQUIRE_ONCE $_zb_path."incs/lib.php";

header("Content-Type:application/json");

if(!$connect) $connect = dbconn();

$stmt = db_query("select * from list where app_no = $app_no");
$resultArray = array();

while($data=mysql_fetch_object($stmt)) { // $data->phoneNumber
$resultArray[] = $data;
}

//Android 측 Code에서는 JSONArray 객체로 받아야 한다.
$json = json_encode($resultArray); //array > json 변환
echo $json;

?>



#결과값 : 

[{"no":"12","app_no":"4","number":"0609002218","regdate":""},{"no":"13","app_no":"4","number":"0609002219","regdate":""},{"no":"14","app_no":"4","number":"0609002246","regdate":""},{"no":"15","app_no":"4","number":"0609002247","regdate":""},{"no":"16","app_no":"4","number":"0609002248","regdate":""},{"no":"17","app_no":"4","number":"0609002249","regdate":""},{"no":"18","app_no":"4","number":"0609050113","regdate":""},{"no":"19","app_no":"4","number":"0609050116","regdate":""},{"no":"20","app_no":"4","number":"0609050117","regdate":""},{"no":"21","app_no":"4","number":"0609057099","regdate":""},{"no":"22","app_no":"4","number":"0609057100","regdate":""},{"no":"23","app_no":"4","number":"0609057575","regdate":""},{"no":"24","app_no":"4","number":"0609058877","regdate":""},{"no":"25","app_no":"4","number":"0609059009","regdate":""}]

댓글 없음:

댓글 쓰기