Error when using some.php?id=$id
I have table named tb_syarat_layanan
. When I try to get JSON, array it shows no Data.
<?php
//Importing database
require_once('koneksi.php');
$query = "select * from tb_syarat_layanan WHERE id_layan=$id";
$hasil = mysqli_query($con,$query);
if(mysqli_num_rows($hasil) > 0 )
{
$response = array();
$response["data"] = array();
while($x = mysqli_fetch_array($hasil))
{
$h['id_layan'] = $x["id_layan"];
$h['dokumen'] = $x["dokumen"];
array_push($response["data"], $h);
}
echo json_encode($response);
}
else
{
$response["message"] = "No Data";
echo json_encode($response);
}
?>
But when I set my $query like this :
$query = "select * from tb_syarat_layanan WHERE id_layan=1";
it show the data that I want
JSON shows no data when $query is set with variable $id