为了账号安全,请及时绑定邮箱和手机立即绑定

如果为空[在php中],如何从检索中跳过图像字段?

如果为空[在php中],如何从检索中跳过图像字段?

PHP
哔哔one 2021-06-17 15:41:34
我正在制作博客系统,其中包含:文本和图像,如果用户不插入图像,则应跳过该图像字段进行检索,同时在每个帖子中显示空图像字段。这段代码有什么问题?或者有什么可能的方法,如果/else 条件语句在 echo 中?$get_posts="SELECT * FROM posts";$run_posts=mysqli_query($con,$get_posts);while($row_post=mysqli_fetch_array($run_posts)){$post_id=$row_post['post_id'];$user_id=$row_post['user_id'];      $post_img=$row_post['post_image'];  $post_cnt=$row_post['post_cnt'];$post_date=$row_post['post_date'];      echo"<div class='posts'><p>$post_date</p>   <p><img src='img/$post_img'width='380'height='auto'/></p><p>$post_cnt</p><a href='single.php?post_id=$post_id'style='float:right;'><button>See Replies or Reply to This</button></a></div><br/>";   }
查看完整描述

3 回答

?
一只萌萌小番薯

TA贡献1795条经验 获得超7个赞

如果$post_img有一些价值,则创建图像标签


if(!empty($post_img)){

echo"<div class='posts'>

    <p>$post_date</p>   

    <p><img src='img/$post_img'width='380'height='auto'/></p>

    <p>$post_cnt</p>

    <a href='single.php?post_id=$post_id'style='float:right;'>

    <button>See Replies or Reply to This</button></a>

    </div><br/>";   

}


查看完整回答
反对 回复 2021-06-19
  • 3 回答
  • 0 关注
  • 122 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信