Show fields if different from 0 (zero)

Asked

Viewed 87 times

0

How to show the fields of each record in the table if the product field is non-zero ?

    </td> 
    </tr>

    <tr>
    <td><?php echo $customer['produto2']; ?></td>
    <td><?php echo $customer['serial2']; ?></td> 
    </tr>

    <tr>
    <td><?php echo $customer['produto3']; ?></td>
    <td><?php echo $customer['serial3']; ?></td> 
    </tr>

    <tr>
    <td><?php echo $customer['produto4']; ?></td>
    <td><?php echo $customer['serial4']; ?></td> 
    </tr>

    <tr>
    <td><?php echo $customer['produto5']; ?></td>
    <td><?php echo $customer['serial5']; ?></td> 
    <tr>                
</tr>
  • That is, I do not want the printing (display) if there is no product, if there is no product, successively. I have tried to fit an if Else, but without success, depending on the display structure !

1 answer

1


You can check if the produtoN exists in the array with the isset() and also check if it is different from 0:

<?php if(isset($customer['produto4']) && $customer['produto4'] != 0) { ?>
    <tr>
        <td><?php echo $customer['produto4']; ?></td>
        <td><?php echo $customer['serial4']; ?></td> 
    </tr>
<?php } ?>
  • 1

    Perfect, very grateful for the help. With variations in isset I get the results I want for each field. Success !

  • The more I learn, I discover that I need to study more, every day. Grateful to all !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.