skip to Main Content

I’m not an expert coder and I don’t was able to find solutions in others many question about it, but I need to understand, please, the right way to insert an if statement between td and /td in a fetch_assoc. The table works fine, and when I put this statement outside the table, it’s all right, but it does’n work when is written inside.
I need to show a label only if the field1 is not empty.

The code is:

<tr><td style=font-weight:bold;>List:</td></tr>;
<tr>td>"if ($row['field1'] > '0' ) echo "This is Field1";"</td>; 
<td style=border-width:0;padding:0.2em;> " . $row["field1"]. " 
</td></tr>;

Thanks in advance.

2

Answers


  1. Chosen as BEST ANSWER

    Thanks Youth Dream. Put in this way:

    <tr><td><?php if ($row[field1] > '0'): ?>This is Field1<?php endif; ?> 
    </td>
    <td style="border-width:0;padding:0.2em"><?php echo $row[field1]; ?></td> 
    </tr>
    

    syntax errors reduced but follow to say that T_STRINGS expecting "," or ";". Any idea about?


  2. To use the if statement in td, you need to wrap the if statement with PHP so that it will recognize the statement correctly and will works.

    Let me provide updated code.

    <tr>
        <td style="font-weight:bold;">List:</td>
    </tr>
    <tr>
        <td>
            <?php if ($row['field1'] > '0'): ?>
                This is Field1
            <?php endif; ?>
        </td>
        <td style="border-width:0;padding:0.2em;">
            <?php echo $row["field1"]; ?>
        </td>
    </tr>
    

    Hope it helps you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search