使用以下代码,我想在天空晴朗时绘制图像sun.png,在天空多云时绘制云,在其他情况下绘制变量......但是有些事情失败了...我总是得到图像变量。 PNG
<?php
if($sky == "clear" ) {
echo '<img src="images/sun.png" width="40">';
}
elseif ($sky == "cloudy" ){
echo '<img src="images/cloud.png" width="40">';
}
else {
echo '<img src="images/variable.png" width="40">';
}
?>
我使用此代码咨询数据库@Jack Goodman
$data_query = mysqli_query($conexionbd,'select * from `weather` where `data` = "2017-03-22" and (`num` = "1" or `num` = "2" or `num` = "3")');
while($data = mysqli_fetch_assoc($data_query)){ ?>
最后我解决了,我的代码出错了,正确的代码是
<?php
if($data['sky'] == "clear" ) {
echo '<img src="images/sun.png" width="40">';
}
elseif ($data['sky'] == "cloudy" ){
echo '<img src="images/cloud.png" width="40">';
}
else {
echo '<img src="images/variable.png" width="40">';
}
?>
答案 0 :(得分:0)
使用switch语句可能会更清楚,然后你可以找到未满足的条件,并用它来调试你的问题:
switch($sky){
case 'clear':
echo '<img src="images/sun.png" width="40">';
break;
case 'cloudy':
echo '<img src="images/cloud.png" width="40">';
break;
default:
echo '$sky is something unknown';
var_dump($sky);
break;
}
答案 1 :(得分:0)