Belajar json sederhana encode decode cool brooo ,,... 3 dan 4 dengan database mysql



contoh json 3


==== start ====
 <?php
   header('Content-type: application/json');
   
    $host = "localhost";
    $user = "root";
    $pass = "";
    $db="wisata_medan";
   
   mysql_connect($host,$user,$pass);
   
   mysql_select_db($db);
   $query = mysql_query("SELECT * FROM `objekwisata`");
   
   $show= array();
   while($k=mysql_fetch_array($query)){
   $show[] = array(
   "id1"=>$k["id"],
   "nama1"=>$k["nama"],
   "alamat1"=>$k["alamat"],
   "keterangan1"=>$k["keterangan"],
   "gambar1"=>$k["gambar"]);
   
   }
   
   $data = array(
   "data" => $show,
   "copyright"=>"Dibuat Oleh MidhighSolution");
   $json = json_encode($data);
   
  echo $json;
   ?>

==== end =====



contoh json 3 1 lagi


==== start ====

 <?php
   header('Content-type: application/json');
   
    $host = "localhost";
    $user = "root";
    $pass = "";
    $db="wisata_medan";
   
   mysql_connect($host,$user,$pass);
   
   mysql_select_db($db);
   $query = mysql_query("SELECT * FROM `objekwisata`");
   
   $show= array();
   $k=mysql_fetch_array($query);
  $show[] = $k;
   
   $data = array(
   "data" => $show,
   "copyright"=>"Dibuat Oleh MidhighSolution");
   $json = json_encode($data);
   
  echo $json;
   ?>

===== end ====




contoh 4


===== start ====

<?php
$server = "127.0.0.1";
$username = "root";
$password = "";
$database = "wisata_medan";

$con = mysql_connect($server, $username, $password) or die ("Could not connect: " . mysql_error());
mysql_select_db($database, $con);

$sql = "SELECT * FROM objekwisata";
$result = mysql_query($sql) or die ("Query error: " . mysql_error());

$records = array();

while($row = mysql_fetch_assoc($result)) {
    $records[] = $row;
}

mysql_close($con);
$data = "{\"toilets\" : ".json_encode($records)."}";
echo $data;  
?>

==== 4 =====



0 Response to "Belajar json sederhana encode decode cool brooo ,,... 3 dan 4 dengan database mysql "

Posting Komentar