Table Data Not Displaying

Posted on 2007-10-01
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
    LVL 50

    Expert Comment

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

    How would I get it to display the "L"s?
    LVL 50

    Expert Comment

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

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

    Expert Comment

    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

    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

    LVL 5

    Expert Comment

    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

    Sorry about that. I mean to display:

    Y as X
    L as L
    N as blank
    LVL 5

    Accepted Solution

    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

    Thanks, that did it!

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    PHP Radio Array 4 28
    PHP foreach DB query 4 22
    Joomla main HTML page 4 20
    Mysqli Query 5 20
    Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now