您好我在code
下面使用city value
来显示database
-
<?php
//echo "SELECT city FROM tbl_city_master WHERE id = ".$rs->city.""
$getCityQuery = mysql_query("SELECT city FROM tbl_city_master WHERE id = ".$rs->city."");
$resultSetCityQuery = mysql_fetch_assoc($getCityQuery);
?>
<? echo '<strong>City-</strong>' ?><? echo $resultSetCityQuery['city'];?>
所有我需要在if else
条件下说没有城市选择 - 我该如何实现该代码
答案 0 :(得分:1)
您可以使用以下代码执行此操作:
$results_count = mysql_num_rows($resultSetCityQuery);
if ($results_count > 0) {
// do something
} else {
echo 'No city Choosen';
}
或者您可以使用mysql_fetch_assoc并检查是否为false:
$results = mysql_fetch_assoc($resultSetCityQuery);
if ($results == false) {
echo 'No city Choosen';
} else {
// do somthing
}
答案 1 :(得分:0)
if (count ($resultSetCityQuery) === 0) echo "No city choosen"
else echo $resultSetCityQuery['city'];
或
if (empty ($resultSetCityQuery)) echo "No city choosen"
else echo $resultSetCityQuery['city'];
答案 2 :(得分:0)
强烈建议您停止使用mysql_ *函数,因为它们将在即将推出的php版本中弃用
您可以检查是否已设置mysql结果
if (count($resultSetCityQuery)>0) {
echo $resultSetCityQuery['city'];
} else {
echo 'No city chosen';
}
答案 3 :(得分:0)
试试这个:
foreach($resultSetCityQuery as $city){
if(isset($city['city']) && !empty($city['city'])){
echo "<strong>City-</strong> {$city['city']} ";
}
}
答案 4 :(得分:0)
此代码将显示可用城市
<?php
$getCityQuery = mysql_query("SELECT city FROM tbl_city_master WHERE id = ".$rs->city."");
if ($getCityQuery)
$resultSetCityQuery = mysql_fetch_assoc($getCityQuery);
?>
<?php
if (resultSetCityQuery != null)
echo "<strong>City-</strong>$resultSetCityQuery['city']";
?>
答案 5 :(得分:0)
尝试以下代码
if(!!$resultSetCityQuery) {
echo $resultSetCityQuery['city'];
} else {
echo "no data found";
or
echo mysql_error($getCityQuery);//if there is an error ragarding to your sql statement
}