Php 这里如何给出if-else
我想在完成第二个if后加入一个else语句,用于等同于helathcare的类别……现在我想要另一个else语句用于财务,但我不能理所当然地将其放置在何处 我有一个混乱的地方,以保持其他金融和2个以上的类别 现在,每当我试图把另外一个放在最后一个位置时,它的if语句是不可更改的,我不知道在哪里再放两个else if语句,再放两个类别Php 这里如何给出if-else,php,if-statement,Php,If Statement,我想在完成第二个if后加入一个else语句,用于等同于helathcare的类别……现在我想要另一个else语句用于财务,但我不能理所当然地将其放置在何处 我有一个混乱的地方,以保持其他金融和2个以上的类别 现在,每当我试图把另外一个放在最后一个位置时,它的if语句是不可更改的,我不知道在哪里再放两个else if语句,再放两个类别 <?php global $row2; if(isset($_POST['category'])) { if($_POST['cate
<?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 } } ?>
?>
?>
您不能将多个else
块与if
块一起放置。但是,您可以使用多个(任意多个)elseif/else if
块以及if
块,如下所示:
if($_POST['category'] == 'Healthcare'){
...
}elseif($_POST['category'] == 'Finance'){
...
}elseif($_POST['category'] == '...'){
...
}else{
...
}
以下是参考资料:您的部分问题似乎是格式不好。如果你为你的If语句排列好打开和关闭标签,我想你会看得更清楚。话虽如此,您可以为我在下面标记的类别if添加任何elseif/if条款:
<!--Blog Post End-->
<?php
} // closes while loop
} else{ } // closes healthcare if, add extra else here
} // closes POST if
else
{
首先,修复代码。您的结束标记未关闭,或在正确的位置关闭。然后使用一些合理的格式,您应该能够看到应该放在哪里。