tags:

views:

79

answers:

5

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 == 'Size') {
          echo '<td> n/a </td>';
        //} elseif ($column == 'Duration') && ($column =='Size') {
        // echo '<td> In Progress </td>';
        } else {
          echo '<td> </td>';
        }
     }
A: 

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.

Chetan
A: 

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.

Unkwntech
+1  A: 
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>";

FatherStorm
you don't want to get into heavliy shelled if statements when a switch statement is easier to use....
FatherStorm
I agree with FatherStorm
Drewdin
A: 

You might be looking for something with an or. Like column = 'blah' or column = 'blah2'.

else if ($column == 'Duration' || $column =='Size') 
CastroXXL
+1  A: 

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>';
}
Mike C
@Mike C- to me this follows the logic i wanted... I tried it, but I can't the page to come up.
cjd143SD
probably because of the typos in my code :/ I'll fix it.
Mike C
@Mike C- thanks
cjd143SD