简体   繁体   English

根据列值显示不同的颜色

[英]Display different colors based on column value

I am fetching values from DB & displaying in php page. 我正在从数据库中获取值并显示在php页面中。

1st row value : attempted 第一行值: 尝试

2nd row value : not 第二行值:

echo $orderrecords[$k]["attempted"];

在此处输入图片说明

now based on column [ attempted ] value, i want to display different colors . 现在基于[尝试]列的值,我想显示不同的颜色。 So when i tried below code, instead of displaying different colors , both rows are displaying value : attempted 因此,当我尝试下面的代码时,而不是显示不同的颜色,两行都显示了value: tryd

if($orderrecords[$k]["attempted"]="attempted")
{
echo '<div style="color: red;">'.$orderrecords[$k]["attempted"].'</div>';
}

else
{
echo '<div style="color: black;">'.$orderrecords[$k]["attempted"].'</div>';
}

在此处输入图片说明

try if($orderrecords[$k]["attempted"]==="attempted") , 尝试if($orderrecords[$k]["attempted"]==="attempted")

=== is used to compare same type and same value, whereas = is just assignment and hence every time you're assigning value attemped to the variable. ===用于比较相同的类型和相同的值,而=只是赋值,因此每次您将attemped的值attemped变量时。

The problem is that you are not comparing the value in your if-condition. 问题在于您没有在if条件中比较该值。 You are setting the value of $orderrecords[$k]["attempted"] in your if-condition. 您正在if条件中设置$ orderrecords [$ k] [“ attatted”]的值。

if($orderrecords[$k]["attempted"] = "attempted")

will always be true 永远是真的

if($orderrecords[$k]["attempted"] == "attempted")

will be true, if the value of $orderrecords[$k]["attempted"] is "attempted" 如果$ orderrecords [$ k] [“ attempted”]的值是“ attempted”,则为true

if($orderrecords[$k]["attempted"] === "attempted")

will be true, if the value of $orderrecords[$k]["attempted"] is "attempted" and the type of $orderrecords[$k]["attempted"] is a string 如果$ orderrecords [$ k] [“ attempted”]的值是“ attempted”并且$ orderrecords [$ k] [“ attempted”]的类型是字符串,则为true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM