PHP for each with an if rule

1

I have a table that gives results of paid and unpaid commissions.

I want it to only bring the paid, that is, if number_format($row->amount_paid,2) = 0 does not bring this line.

<?php 
    $i=-1;
    foreach($this->rows->rows as $row){?>
        <tr class="sectiontableentry<?php echo ($i%2)+1;?>">
            <td><?php echo $row->name; ?></td>
            <td align="right"><?php echo empty($row->timestamp) ? '' : date('Y-m-d',$row->timestamp); ?></td>
            <td align="right"><?php echo $row->order_number; ?></td>
            <td align="right"><?php echo number_format($row->order_total,2); ?></td>
            <td align="right"><?php echo number_format($row->commission,2); ?></td>
            <td align="right"><?php echo number_format($row->amount_paid,2);?></td>
            <td align="right"><?php echo number_format($row->balance,2); ?></td>
            <td><?php echo $row->note; ?>&nbsp;</td>
        </tr>
<?php  }?>

I believe you have to use if somewhere, correct? But I do not know how.

    
asked by anonymous 17.02.2017 / 15:10

1 answer

1

Just put if inside loop , before any HTML code, conditioning it:

<?php 
  $i=-1;
  foreach($this->rows->rows as $row):
    if (number_format($row->amount_paid,2) != 0):
?>
      <tr class="sectiontableentry<?php echo ($i%2)+1;?>">
        <td><?php echo $row->name; ?></td>
          <td align="right"><?php echo empty($row->timestamp) ? '' : date('Y-m-d',$row->timestamp); ?></td>
          <td align="right"><?php echo $row->order_number; ?></td>
          <td align="right"><?php echo number_format($row->order_total,2); ?></td>
          <td align="right"><?php echo number_format($row->commission,2); ?></td>
          <td align="right"><?php echo number_format($row->amount_paid,2);?></td>
          <td align="right"><?php echo number_format($row->balance,2); ?></td>
          <td><?php echo $row->note; ?>&nbsp;</td>
        </tr>
<?php
    endif;
  endforeach;
?>
  

Note : The value of the variable i does not change inside the loop, I think you probably forgot to increment it.

    
17.02.2017 / 15:24