我想在没有图像时隐藏我的html div,并在我有图像时显示它。我怎么能用PHP做到这一点? 这是我的代码
<?php
$imgsql=mysqli_query($link,"select eve_pic,eve_pic2,eve_pic3,eve_pic4 from event_tbl");
?>
<div class="col-md-3 col-sm-6 col-xs-12" <?php if(mysqli_num_rows($imgsql)>0){
$imgrow=mysqli_fetch_array($imgsql);
?> style="visibility:visible;"<?php }?> <?php else { ?> style="display:none" <?php}?> >
<div class=sz_portfolio_003_trig_wrap>
<div class=sz_portfolio_003_trig_img>
<div class=sz_portfolio_003_trig_btn>
<a href=#sz_portfolio_003_4_col data-backdrop=true data-slide-to=0 data-toggle=modal>
<img src="admin/uploads/eventpics/<?php echo $imgrow['eve_pic'];?>" alt="sz_portfolio_003_01" width="200px" height="200px" class="imagen"/></a>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
您需要使用If语句来获得所需内容。要了解有关If语句的更多信息,请阅读here
改变这个:
UIEdgeInsets
对此:
<?php
$imgsql=mysqli_query($link,"select eve_pic,eve_pic2,eve_pic3,eve_pic4 from event_tbl");
?>
<div class="col-md-3 col-sm-6 col-xs-12" <?php if(mysqli_num_rows($imgsql)>0){
$imgrow=mysqli_fetch_array($imgsql);
?> style="visibility:visible;"<?php }?> <?php else { ?> style="display:none" <?php}?> >
<div class=sz_portfolio_003_trig_wrap>
<div class=sz_portfolio_003_trig_img>
<div class=sz_portfolio_003_trig_btn>
<a href=#sz_portfolio_003_4_col data-backdrop=true data-slide-to=0 data-toggle=modal>
<img src="admin/uploads/eventpics/<?php echo $imgrow['eve_pic'];?>" alt="sz_portfolio_003_01" width="200px" height="200px" class="imagen"/></a>
</div>
</div>
</div>
</div>
答案 1 :(得分:0)
<div class="col-md-3 col-sm-6 col-xs-12" style="<?php
if (mysqli_num_rows($imgsql)>0){
$imgrow=mysqli_fetch_array($imgsql);
echo "display:block;"}
else { echo "display:none"};
?>"...
答案 2 :(得分:0)
只需将其更改为:
<?php if(!empty($imgrow['eve_pic']))?>{
<div class=sz_portfolio_003_trig_wrap>
<div class=sz_portfolio_003_trig_img>
<div class=sz_portfolio_003_trig_btn>
<a href=#sz_portfolio_003_4_col data-backdrop=true data-slide-to=0 data-toggle=modal>
<img src="admin/uploads/eventpics/<?php echo $imgrow['eve_pic'];?>" alt="sz_portfolio_003_01" width="200px" height="200px" class="imagen"/></a>
</div>
</div>
</div>
<?php } ?>
如果图像存在,则只显示div。