dqhdpppm02183 2018-06-23 10:47
浏览 18
已采纳

变量总是取相同的值[重复]

This question already has an answer here:

I have a select from the database working fine, all the fields are comming correct, but in the php file I created an if to chech if the updates= to 0 or 1, but is not working, the varialbe $up always assume the same value although in the database are diferent.

I want a thumbs up if the database value is 1 and a thumbs down is the database value is 0.

database print

result print

 <?php
 include ("db.php");
    $admin_query="SELECT id, nome, email, updates FROM atualizacao";
     $run_query = mysqli_query($con,$admin_query);

    if (mysqli_num_rows($run_query) > 0){

        while($row = mysqli_fetch_array($run_query)){
            $id=$row['id'];
            $nome=$row['nome'];
            $email=$row['email'];
            $updates=$row['updates'];
            if($updates="0"){
                $up="<i class='fa fa-thumbs-down' style='font-size:24px'></i>" ; 
            }else{
                $up="<i class='fa fa-thumbs-up' style='font-size:24px'></i>";
            }
           echo
            "<div class='card mx-auto w-100'>
                <div class='card-body'>
                        <div class='row'>
                        <div class='col-md-2' style='text-align: center'>$id</div>
                        <div class='col-md-2' style='text-align: center'>$nome</div>
                        <div class='col-md-2' style='text-align: center'>$email</div>
                        <div class='col-md-2' style='text-align: center'>$up</div>
                    </div>
                </div>
            </div>
           ";
       }
    }
    ?>
</div>
  • 写回答

1条回答 默认 最新

  • dopgv00024 2018-06-23 10:51
    关注

    You are not making a comparison but an assignment in your condition:

    if($updates="0")
    

    This will always return true, you need to change it to:

    if ($updates == "0")
    

    See the comparison operators in PHP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器