Skip to content

Instantly share code, notes, and snippets.

@mkhuda
Last active December 16, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkhuda/5476731 to your computer and use it in GitHub Desktop.
Save mkhuda/5476731 to your computer and use it in GitHub Desktop.
<?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