I have 2 query the result of which I will use in JSON . The first query is
$query = "SELECT *
FROM info_lokasi
WHERE id_lokasi=".$id."";
and the second query
$query = "SELECT t1.id_lokasi,t1.jalan,t1.lat,t1.lng,t1.nama,t2.kapasitas,t2.kegiatan,t2.parkir,t2.pengurus
FROM info_lokasi t1
INNER JOIN detail t2 ON t1.id_lokasi=t2.id_lokasi
WHERE t1.id_lokasi
AND t2.id_lokasi=".$id."";
when I use the first query , the result I get is
[
{
"id_lokasi": "3",
"nama": "masjid",
"jalan": "surabaya",
"lat": "-7.292958471571183",
"lng": "112.71161556243896",
"username": "ope",
"jenis": "masijd"
}
]
but, when I use a second query , I did not get the result. WHY?
this is my code:
PHP
<?php
include "db.php";
header("Content-type: text/javascript");
if (isset($_POST['detail'])) {
$id = $_POST['id'];
$query = "SELECT t1.id_lokasi,t1.jalan,t1.lat,t1.lng,t1.nama,t2.kapasitas,t2.kegiatan,t2.parkir,t2.pengurus FROM info_lokasi t1 INNER JOIN detail t2 ON t1.id_lokasi=t2.id_lokasi WHERE t1.id_lokasi AND t2.id_lokasi=".$id."";
//$query = "SELECT * FROM info_lokasi WHERE id_lokasi=".$id."";
$data = $con->query($query);
$results = array();
while ($r = mysqli_fetch_array($data,MYSQL_ASSOC)) {
# code...
$results[] = $r;
}
echo json_encode($results);
}
mysqli_close($con);
?>
Javascript
function detail(idlokasi){
var id = idlokasi;
var datastring = "id="+id+"&detail=";
$.ajax({
type: "POST",
url: "http://localhost:8080/maps-api/detail.php",
data: datastring,
crossDomain: true,
cache: false,
datatype: "JSON",
success: function(data){
alert("DATA: "+data);
}
});
}
Thanks