0

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.

1
  • Did you skip the "Operators" section of your tutorial? Commented Jun 12, 2011 at 4:40

2 Answers 2

1

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
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I am a high school student and still trying to learn all of this.
0

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){
...
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.