Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP If和else语句-_Php_Mysql_If Statement_Exit - Fatal编程技术网

PHP If和else语句-

PHP If和else语句-,php,mysql,if-statement,exit,Php,Mysql,If Statement,Exit,我从mySQL数据库中提取图像和信息,并使用一些PHP函数进行显示。有时所有的信息都不在那里,我需要它基本上显示:无但我似乎无法得到它-我错过了什么?以下是我的显示功能: <?php if ($recipe->hassliderimage5 == true) { $recipe->show_image_carousel5(); } else { } ?> 这是我为我想要的工作所得到的——不确定这是否是最好的解决方案?我对PHP还是有点陌生 &l

我从mySQL数据库中提取图像和信息,并使用一些PHP函数进行显示。有时所有的信息都不在那里,我需要它基本上
显示:无但我似乎无法得到它-我错过了什么?以下是我的显示功能:

<?php if ($recipe->hassliderimage5 == true) { 
   $recipe->show_image_carousel5();
    } else {
    }

?>
这是我为我想要的工作所得到的——不确定这是否是最好的解决方案?我对PHP还是有点陌生

<?php if ($recipe->hassliderimage5 == true) { ?>
      <div id="sliderimageFive" class="item">
            <?php   
                $recipe->show_image_carousel5();
            ?> 
       </div>    
<?php } ?>

在收集必须显示的数据之前,您似乎犯了创建视图的错误。更合理的应用程序结构是从数据库获取数据,验证数据,然后根据您拥有的数据量和类型创建视图


另外,看看这个:

我不能评论,因为我没有足够的声誉,所以我试着回答

为什么要在mysql_result($this->result,0,“imageCarousel5”)上使用trim!=''此代码将为您提供true或false无需修剪的字符串

也许你想修剪mysql_结果的返回,然后检查它是否为空

if (trim(mysql_result($this->result,0,"imageCarousel5")) != '') {$this->hassliderimage5 = true;} else {$this->hassliderimage5 = false;}
尝试以下测试:

<?php if (filter_var(recipe->hassliderimage5, FILTER_VALIDATE_BOOLEAN) == true) { 
   $recipe->show_image_carousel5();
} else {
   // do other
}
?>

如果'recipe->hasliderimage5'的值为“1”,“true”,“on”和“yes”,则返回true

享受你的代码

<?php if (filter_var(recipe->hassliderimage5, FILTER_VALIDATE_BOOLEAN) == true) { 
   $recipe->show_image_carousel5();
} else {
   // do other
}
?>