• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

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

?>
0
fcruz5
Asked:
fcruz5
  • 4
  • 3
  • 2
1 Solution
 
Steve BinkCommented:
>>>      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'.
0
 
fcruz5Author Commented:
How would I get it to display the "L"s?
0
 
Steve BinkCommented:
Remove the if statement from the echo.

echo ('<td class=' . $css_class . ' align=default >'.$val[1].'&nbsp</td>');
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
frinCommented:
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
0
 
fcruz5Author 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

0
 
frinCommented:
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>');
0
 
fcruz5Author Commented:
Sorry about that. I mean to display:

Y as X
L as L
N as blank
0
 
frinCommented:
Then use this:

if ($val[1] == 'Y') $temp = 'X';
elseif ($val[1] == 'N') $temp = '';
else $temp = $val[1];
      echo ('<td class=' . $css_class . ' align=default >'.$temp.'&nbsp</td>');

This will change Y to X, N to blank and leave everything else as it is, store to $temp and display the variable.
0
 
fcruz5Author Commented:
Thanks, that did it!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now