Link to home
Start Free TrialLog in
Avatar of fcruz5
fcruz5Flag for United States of America

asked on

Table Data Not Displaying

Hi,

I have the following table data that displays for example like the following:

X          23          14
            10          69
X            2          40
X          94          33
            60          98
            25          55
X          51            7

====================

This is how it used to look:

Y          23          14
L          10          69
Y            2          40
Y          94          33
N          60          98
L          25          55
Y          51            7

All the "Y"s display as an "X" and all the "N"s display as blank. But, when there is an "L", it displays it as blank. I want the "L"s to be displayed.

How can I get the "L"s to display? Below, is the PHP code:

<?php

echo "<table cellpadding=\'2\' cellspacing=\'0\'>";

echo "<tr>";
echo "<td class=\"th\" >col1</td>";
echo "<td class=\"th\" >col2</td>";
echo "<td class=\"th\" >col3</td>";

if($result && mysql_num_rows($result) > 0)
{    for ($i = 0; $i < mysql_num_rows($result); $i++) {
    $resultArray[$i] = mysql_fetch_array($result);
}

foreach ($resultArray as $val) {
   echo ('<tr>');//first row
   if (($rowcount%2) == 0) {
        $css_class = "\"row\"";
    } else {
        $css_class = "\"alt\"";
    }

      echo ('<td class=' . $css_class . ' align=default >'.($val[1] == 'Y' ? 'X' : '').'&nbsp</td>');
      echo ('<td class=' . $css_class . ' align=default >'.$val[2].'</td>');
      echo ('<td class=' . $css_class . ' align=default >'.$val[3].'</td>');
    echo ('</tr>');
}


} // end if results
echo ('</table>');

?>
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

>>>      echo ('<td class=' . $css_class . ' align=default >'.($val[1] == 'Y' ? 'X' : '').'&nbsp</td>');
>>>      echo ('<td class=' . $css_class . ' align=default >'.$val[2].'</td>');
>>>      echo ('<td class=' . $css_class . ' align=default >'.$val[3].'</td>');

It is displaying exactly what you are telling it to.  The first line says "if the value stored in index 1 of val is equal to 'Y', then display 'X', otherwise display nothing."  This will print nothing but 'X', and only for values of 'Y'.
Avatar of fcruz5

ASKER

How would I get it to display the "L"s?
Remove the if statement from the echo.

echo ('<td class=' . $css_class . ' align=default >'.$val[1].'&nbsp</td>');
just turn the results:

      echo ('<td class=' . $css_class . ' align=default >'.($val[1] == 'N' ? '' : 'X').'&nbsp</td>');

this will show X for all but N
Avatar of fcruz5

ASKER

With the code that I have already, it will show X for all but N, which is fine.

But other than that, I want the L to be displayed as L. Right now, it displays blank.

This is what I am getting:

X as Y
N as blank
L as blank ( I need this one to display as is and not blank)

Hope this makes sense

The code snipper I gave will display Y as X, L as X, N as blank.

But if you want to display Y as Y, L as L, N as blank, use this:

      echo ('<td class=' . $css_class . ' align=default >'.($val[1] == 'N' ? '' : $val[1]).'&nbsp</td>');
Avatar of fcruz5

ASKER

Sorry about that. I mean to display:

Y as X
L as L
N as blank
ASKER CERTIFIED SOLUTION
Avatar of frin
frin
Flag of Slovenia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fcruz5

ASKER

Thanks, that did it!