Last active
December 16, 2015 18:19
-
-
Save mkhuda/5476731 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//memberi pengalamatan khusus untuk json | |
header('Content-type: application/json'); | |
//memanggil database | |
$host="localhost"; | |
$user="nama user"; | |
$password="password db"; | |
$koneksi=mysql_connect($host,$user,$password) or die("Gagal Koneksi Bro !"); | |
mysql_select_db("nama db"); | |
//query data | |
$sql = "SELECT id, namacewek AS namaceweknya FROM cewek ORDER BY id "; | |
$result = mysql_query($sql) or die ("Query error: " . mysql_error()); | |
//fetch dalam bentuk array | |
$records = array(); | |
while($row = mysql_fetch_assoc($result)) { | |
$records[] = $row; | |
} | |
//menuliskannya dalam bentuk json menggunakan fungsi json_encode | |
echo $_GET['jsoncallback'] . '(' . json_encode($records) . ');'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment