Table Data Not Displaying

Posted on 2007-10-01
Medium Priority
Last Modified: 2013-12-13

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:


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

Question by:fcruz5
  • 4
  • 3
  • 2
LVL 51

Expert Comment

by:Steve Bink
ID: 19991572
>>>      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 Comment

ID: 19991588
How would I get it to display the "L"s?
LVL 51

Expert Comment

by:Steve Bink
ID: 19991599
Remove the if statement from the echo.

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

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Expert Comment

ID: 19991620
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 Comment

ID: 19992017
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


Expert Comment

ID: 19992074
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 Comment

ID: 19992184
Sorry about that. I mean to display:

Y as X
L as L
N as blank

Accepted Solution

frin earned 2000 total points
ID: 19992806
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.

Author Comment

ID: 19992968
Thanks, that did it!

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question