I want to display data from database with condition when data is not found will return string value "data not available or already deleted"
$Q = mysql_query("SELECT *
FROM geosekolah
JOIN kecamatan USING (id_kecamatan)
JOIN kelurahan USING (id_kelurahan)
where id_sekolah=".$id )
or die(mysql_error());
if($Q){
$posts = array();
if(mysql_num_rows($Q))
{
while($post = mysql_fetch_assoc($Q)){
$posts[] = $post;
}
}
$data = json_encode(array('results'=>$posts));
if (!mysql_num_rows($Q)) {
echo "data not available or already deleted";
exit;
}
}
above is the code I created but it did not work. when the data is contained in the database, always display the string "data not available or already deleted" how to solve the problem, thanks for everyone who has helped answer.