2015년 5월 12일 화요일

using json on php

PHP5.3 , JSON

Example.php
================================================================
<?
require_once('inc/connect.php'); // your connect information

//sample query
$query = "SELECT * FROM TABLE1 WHERE 1 ";
$result = mysqli_query($link,$query);

$result_array = array();

while( $row = mysqli_fetch_array( $result, MYSQLI_ASSOC ) ){
$result_array[] = $row;
};

// encode to json
$result_array = json_encode( $result_array );

// print result
echo $_GET['callback'] . '(' .$result_array. ')';

mysqli_free_result($result);
mysqli_close($link);
?>

댓글 없음:

댓글 쓰기