如何在if和else语句中使用等号运算符

时间:2019-06-02 16:53:29

标签: php

我一直在尝试适当地使用等号运算符通过if和else语句回显某些变量,但是我的等号运算符没有相应地回显。

<?php 
    $sql        = "SELECT * FROM customer_id_verification WHERE status='0'";
    $not_id_verify     = $database->query($sql);
    $id_verification   = $database->fetch_array($not_id_verify);
    $fetch_id          = $database->escape_value($id_verification['status']);

    $sql       = "SELECT * FROM customer_utility_verification WHERE status='0'";
    $not_util_verify        = $database->query($sql);
    $utility_verification   = $database->fetch_array($not_util_verify);
    $fetch_util             = $database->escape_value($utility_verification['status']);
?>
<?php 
    $sql        = "SELECT * FROM customer_id_verification WHERE status='1'";
    $id_verify         = $database->query($sql);
    $id_verification   = $database->fetch_array($id_verify);
    $fetch_ids          = $database->escape_value($id_verification['status']);

    $sql       = "SELECT * FROM customer_utility_verification WHERE status='1'";
    $util_verify            = $database->query($sql);
    $utility_verification   = $database->fetch_array($util_verify);
    $fetch_utils            = $database->escape_value($utility_verification['status']);

?>

我希望每个if and else语句一次显示一个“ li”语句。

<?php 
      if($fetch_id == $fetch_util = 0){
    ?>  
    <li class="list-group-item"><a class="btn btn-outline-danger" data-toggle="collapse" href="#collapsidentification" role="button" aria-expanded="false" aria-controls="collapseExample">
    Verify Your account </a></li>
  <?php   
      }else{
    if($fetch_ids == $fetch_utils = 1){
        ?>
    <li class="list-group-item"><a class="btn bg-success" data-toggle="collapse" role="button" aria-expanded="false" aria-controls="collapseExample">
    Account Verified </a></li>
    <?php             
    }
  ?>
    <li class="list-group-item"><a class="btn btn-outline-warning" data-toggle="collapse" href="" role="button" aria-expanded="false" aria-controls="collapseExample">
    Verification Pending </a></li> 
 <?php 
      }
  ?>

1 个答案:

答案 0 :(得分:0)

$fetch_id == $fetch_util = 0

实际上,您将$ fetch_util设置为0。'='是赋值运算符。这意味着从数据库中检索到的值     $ fetch_util = $ database-> escape_value($ utility_verification ['status']); 被'0'覆盖

相同
$fetch_ids == $fetch_utils = 1

您正在将$ fetch_utils的值设置为'1'