如何在这里给出if if

时间:2018-04-17 16:49:59

标签: php if-statement

我希望在第二个if之后的块完成后包含一个else语句,如果类别等于helathcare ....现在我想要另外一个用于融资但是我没有得到那个令人兴奋的地方放置其他 我对于在哪里保留其他财务和另外两个类别感到困惑 现在,每当我试图将其他人放在最后一个对其if语句不可知的时候,我不知道如果另外两个以上的其他地方放置2个其他地方

<?php
global $row2;
if(isset($_POST['category']))
{
            if($_POST['category']== 'Healthcare')
            {

            $query = "select *from event where category = 'Healthcare';";
            $result=mysqli_query($conn,$query)or die(mysqli_error($conn));
             while($row2= mysqli_fetch_array($result)) 
             {
            ?>
    <div class="events events-full event-list">
      <div class="container">
        <div class="row">
          <div class="col-md-9 col-sm-8"> 
            <!--Blog Post Start-->
            <div class="blog-post">
              <div class="post-thumb">
                <div class="link-wrap"> <a href="#"><i class="fa fa-search"></i></a> <a href="#"><i class="fa fa-link"></i></a> </div>
                <img src="images/gallery/<?php echo $row2['event_image']?>" alt='user'></div>
              <div class="event-text">
                <div class="event-counter"></div>
                <h4> <a href="#"><?php echo($row2['title']); ?></a> </h4>
                <p><?php echo($row2['descrption']); ?></p>
                <p><span class="glyphicon glyphicon-map-marker"><?php echo($row2['location']); ?></span></p>
                <p><span class="glyphicon glyphicon-grain"><?php echo($row2['organizer']); ?></span></p>
                <a class="nd" href="">
                  <form action="eventdetail.php" method="post">

<input type='hidden' value="<?php echo $row2['id']; ?>" name='id'/>


<button type="submit" class="btn btn-primary" name="detail" value=”detail”>Event Detail</button>
            </div>
                </a> </div>
            </div>
          </form>

            <!--Blog Post End-->
  <?php } 








}




}

        else
        {


              global $row2;
            $query = "select *from event;"  ;
            $result=mysqli_query($conn,$query)or die(mysqli_error($conn));
             while($row2= mysqli_fetch_array($result)) 
             {
            ?>
    <div class="events events-full event-list">
      <div class="container">
        <div class="row">
          <div class="col-md-9 col-sm-8"> 
            <!--Blog Post Start-->
            <div class="blog-post">
              <div class="post-thumb">
                <div class="link-wrap"> <a href="#"><i class="fa fa-search"></i></a> <a href="#"><i class="fa fa-link"></i></a> </div>
                <img src="images/gallery/<?php echo $row2['event_image']?>" alt='user'></div>
              <div class="event-text">
                <div class="event-counter"></div>
                <h4> <a href="#"><?php echo($row2['title']); ?></a> </h4>
                <p><?php echo($row2['descrption']); ?></p>
                <p><span class="glyphicon glyphicon-map-marker"><?php echo($row2['location']); ?></span></p>
                <p><span class="glyphicon glyphicon-grain"><?php echo($row2['organizer']); ?></span></p>
                <a class="nd" href="">
                  <form action="eventdetail.php" method="post">

<input type='hidden' value="<?php echo $row2['id']; ?>" name='id'/>


<button type="submit" class="btn btn-primary" name="detail" value=”detail”>Event Detail</button>
            </div>
                </a> </div>
            </div>
          </form>

            <!--Blog Post End-->
            <?php  } } ?>

       ?>

2 个答案:

答案 0 :(得分:0)

您无法将多个else块与if块一起放置。但是,您可以使用多个(尽可能多的)elseif/else if块以及if块,如下所示:

if($_POST['category'] == 'Healthcare'){
    ...
}elseif($_POST['category'] == 'Finance'){
    ...
}elseif($_POST['category'] == '...'){
    ...
}else{
    ...
}

以下是参考: http://php.net/manual/en/control-structures.elseif.php

答案 1 :(得分:0)

您的部分问题似乎是格式不佳。如果你为if语句排列开放和关闭标签,我认为你可以更好地看到它。话虽如此,如果我在下面标记的地方,您可以为该类别添加任何elseif / if子句:

<!--Blog Post End-->
<?php 
} // closes while loop

} else{ } // closes healthcare if, add extra else here

} // closes POST if

else
{