We help IT Professionals succeed at work.

New podcast episode! Our very own Community Manager, Rob Jurd, gives his insight on the value of an online community. Listen Now!

x

Table Data Not Displaying

fcruz5
fcruz5 asked
on
210 Views
Last Modified: 2013-12-13
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>');

?>
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2004

Commented:
>>>      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'.

Author

Commented:
How would I get it to display the "L"s?
CERTIFIED EXPERT
Top Expert 2004

Commented:
Remove the if statement from the echo.

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

Commented:
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

Author

Commented:
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

Commented:
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>');

Author

Commented:
Sorry about that. I mean to display:

Y as X
L as L
N as blank
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks, that did it!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.