How would I get some text to display only if certain rows equal 1. I have a table and there are I have fields labeled 'SEC1', 'SEC2', and 'SEC3'. I can get it to display text for just one equaling to one, but I want something were the fields above have to equal one in order for the text to show.
Any help is appreciated
This is what I am using to get it to work for one:
$Completed = ($row["SEC1"] == 1) ? "Completed!" : $row[""]; echo $Completed;
Is it possible to modify that to get it to work? I'd be fine with having them added together to equal 3 instead of one.
If you mean that any of the three fields independently equals "1" then this will do it :
if (($row["SEC1"] == 1)||($row["SEC2"] == 1)||($row["SEC3"] == 1)){
//Do what you what
}
Or if you mean all three of them combined equal "3" then :
if (($row["SEC1"] + $row["SEC2"] + $row["SEC3"]) == 3){
//Do what you what
}
Why use the ternary operator? Use the 'and' operator to build more complex conditional statements:
$Completed = "";
if (($row["SEC1"] == 1) && ($row["SEC2"] == 1) && ($row["SEC3"] == 1)) {
$Completed = "Completed!";
}
echo $Completed;
There are a lot of different ways you could go about solving this
if ($row["SEC1"] + $row["SEC2"] + $row["SEC3"] == 3){
...
}