php - how to echo if rows no data found in php
问题描述
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.
解决方案
推荐阅读
- django-filter - 如何过滤石墨烯-django中为空的石墨烯标量场?
- c# - 运行日历时找不到表 0
- javascript - 如何在javascript中将背景颜色从白色慢慢淡化为红色
- android - 使用开放天气 API 时如何显示天气图标?
- gnuradio - 使用 gnuradio-companion 支持编译 gnuradio-3.8.0.0
- c# - c#线程停止而不抛出错误
- c# - 如何发布我在复选框中选中或取消选中的选项
- jmeter - 使用 Jmeter 执行分布式负载测试时的端口
- c# - Rijndael not decrypting correctly
- amazon-web-services - 如何使用本地文件夹而不是 S3 存储桶作为集合?