使用和多个else if语句输出意外的文件结尾

时间:2016-12-19 06:39:58

标签: php

我一直试图回应代码,但它无法正常工作。在阅读ifelse语句之后,我仍然无法想象在php输出意外的文件结尾时这句话有什么问题。

       <?php if($current_type){?>
       <?php echo " Manage Product Type ";      
       echo "Menu Name:".  $current_type["product_type"]."<br>";?>  
       <a href= "edit_category.php">Edit Subject</a>;
       <?php}elseif($current_category){?>
        <h1> Manage Product category </h1>
       <?php echo "Menu Name:".  $current_category["category_name"];?>
      <?php}elseif ($current_product){?>
        <h1> Manage Products </h1>
      <?php echo "Menu Name:".  $current_product["product_names"];?>
      <?php }else{?>
        Please select a Product, category, or type
       <?php};?>

3 个答案:

答案 0 :(得分:1)

这是对代码可读性的巨大改进。它使用PHP alternate syntax for control structures

<?php if($current_type): ?>
  <h1>Manage Product Type</h1>
  Menu Name: <?php echo $current_type["product_type"] ?><br>
  <a href="edit_category.php">Edit Subject</a>
<?php elseif ($current_category): ?>
  <h1>Manage Product category</h1>
  Menu Name: <?php echo $current_category["category_name"] ?>
<?php elseif ($current_product): ?>
  <h1>Manage Products</h1>
  Menu Name <?php echo $current_product["product_names"] ?>
<?php else: ?>
  Please select a Product, category, or type
<?php endif ?>

答案 1 :(得分:0)

试试这个,

   <?php if($current_type){ ?>
   <?php echo " Manage Product Type ";      
   echo "Menu Name:".  $current_type["product_type"]."<br>";?>  
   <a href= "edit_category.php">Edit Subject</a>;
   <?php } else if($current_category){ ?>
    <h1> Manage Product category </h1>
   <?php echo "Menu Name:".  $current_category["category_name"];?>
  <?php } else if ($current_product){?>
    <h1> Manage Products </h1>
  <?php echo "Menu Name:".  $current_product["product_names"];?>
  <?php } else {?>
    Please select a Product, category, or type
   <?php }?>

答案 2 :(得分:0)

Use this rationale

<?php if(1 == 1) { ?>
    <?php echo "xxxxx"; ?>
<?php } elseif(1 == 2) { ?>
    <?php echo "xxxxx"; ?>
<?php } elseif (1 == 3){ ?>
    <?php echo "xxxxx"?>
<?php } else { ?>
    <?php echo "xxxxx"?>
<?php } ?>