help with php AND condition
Need help reworking this php code/logic. Right now, if I have no value for either column 'Duration' or 'Size', my html table is blank and I put a default value of n/a
.
I want to change the logic to continue to handle that condition and give an n/a
value, but also add the logic to read if BOTH are n/a
, then set my column 'Status' value = 'In Progress'.
Somehow, my commented code isn't working right. Thanks.
foreach ($keys as $column){
if (isset($row[$column])){
if ($column == 'Server'){
echo '<td> <a href="' . $server_array[$row[$column]] . '">' . $row[$column] . '</a></td>';
} elseif ($column == 'Status'){
echo '<td> <font color="' . $color_array[$row[$column]] . '">' . $row[$column] . '</font></td>';
} else {
echo '<td>' . $row[$column] . '</td>';
}
} elseif ($column == 'Status') {
echo '<td><font color="yellow"> Review </font></td>';
} elseif ($column == 'Duration') {
echo '<td> n/a </td>';
} elseif ($column == 'Si开发者_StackOverflow社区ze') {
echo '<td> n/a </td>';
//} elseif ($column == 'Duration') && ($column =='Size') {
// echo '<td> In Progress </td>';
} else {
echo '<td> </td>';
}
}
try this
} elseif ($column == 'Status') {
if (!isset($row['Duration']) && !isset($row['Size']))
echo '<td> In Progress </td>';
else
echo '<td><font color="yellow"> Review </font></td>';
}
instead of
} elseif ($column == 'Status') {
echo '<td><font color="yellow"> Review </font></td>';
}
switch ($column){
case "Status":
$html="<font color="yellow"> Review </font>";
break;
case "Duration":
case "Size":
$html="n/a";
break;
case "SOME_OTHER_SOMETHING":
$html=" In Progress ";
break;
default:
$html="";
break;
}
echo"<td>$html</td>";
The commented out code should be:
} elseif (($column != 'Duration') && ($column != 'Size')) {
echo '<td> In Progress </td>';
...assuming you want it to say In Progress
when column
is not Duration
or Size
.
Note that with this logic, the last else
will never be reached, so it can just be removed.
Also, the question could be made clearer, as I'm not sure exactly what you're trying to achieve.
You need to either drop a few parens or add a few, so that ($column == 'Duration') && ($column =='Size')
becomes (($column == 'Duration') && ($column =='Size'))
or ($column == 'Duration' && $column =='Size')
But you have a bigger problem see R. Bemrose's comment on your question.
You might be looking for something with an or. Like column = 'blah' or column = 'blah2'.
else if ($column == 'Duration' || $column =='Size')
精彩评论