prints only 1 row

Discussion in 'PHP' started by pshaw, Apr 11, 2021.

  1. #1
    Hi guys finally got a slew of files figured out but this one - I hate it!
    I had it working displaying all five rows but now displays only the first. Please, what's wrong?
    ------------------------------
    the code:
    <?php error_reporting (E_ALL ^ E_NOTICE);
    
    // Include config file
    require_once "getprerentdb.php";
    
    //MySqli Select Query
    $results = $mysqli->query ("SELECT * FROM paytbl");
    
    //Print version
       //Set at what record to break at 25 records per page
       $BreakAT=25; 
       $num=0;
       $pagenum = 1;
       $totpaid=0;
      // ---------------------------------------
      while($row = mysqli_fetch_array($results))  {
    // ----------------------------------------
       if($num % $BreakAT == 0)
      {
    if($num>0)
      
        { echo '</table class="print">';
            echo '<div class="breakhere"></div>';
            $pagenum++; }
        echo date('m/d/y');
         echo " Page " . $pagenum;
    ?>
       <div class="title">Payment Report</div><br />
       <table align="center" cellspacing=0 cellpadding=0 border=1>
       <thead>
         <tr>
    <th>tenant</th>
    <th>unit</th>
    <th>rent paid</th>
    <th>rent due</th>
    <th>prev bal</th>
    <th>late chg</th>
    <th>sec dep</th>
    <th>damage</th>
    <th>court cost</th>
    <th>nsf</th>
    <th>hud pay</th>
    <th>tenant pay</th>
    <th>date paid</th>
    <th>late</th>
    <th align=left>comment</th>
         </tr>
       </thead>
    <?php   
       $totpaid += $row['paidsum']; 
      echo '
       <tr>
    <td>' . $row['tenant'] . '</td>
    <td>' . $row['unit'] . '</td>
    <td align=right class="currency">$'.number_format($row['rentpaid'],2).'</td>  
    <td align=right class="currency">$'.number_format($row['rentdue'],2).'</td>
    <td align=right class="currency">$'.number_format($row['prevbal'],2).'</td>
    <td align=right class="currency">$'.number_format($row['latechg'],2).'</td>
    <td align=right class="currency">$'.number_format($row['secdep'],2).'</td>
    <td align=right class="currency">$'.number_format($row['damage'],2).'</td>
    <td align=right class="currency">$'.number_format($row['courtcost'],2).'</td>
    <td align=right class="currency">$'.number_format($row['nsf'],2).'</td>
    <td align=right class="currency">$'.number_format($row['hudpay'],2).'</td>
    <td align=right class="currency">$'.number_format($row['paidsum'],2).'</td>
    <td>' . $row['datepaid'] . '</td>
    <td>' . $row['late'] . '</td>
    <td>' . $row['comments'] . '</td>
       </tr>';
         $num++;
      }
    }
      echo '
       <tr>
         <th scope="row" colspan="11">Total Paid:</th>
         <td bgcolor="#FFD4D4" class="currency">' . number_format($totpaid, 2, '.', '') . '</td>
       </tr>
    </table>';
    ?>  
    </center></div></body></html>
    PHP:
    ------------------------------
    the result:
    04/11/21 Page 1
    Payment Report

    tenant unit rent paid rent due prev bal late chg sec dep damage court cost nsf hud pay tenant pay date paid late comment
    tenant1 apt1 $540.00 $530.00 $0.00 $10.00 $0.00 $0.00 $0.00 $0.00 $0.00 $540.00 12/20/2020 L
    Total Paid: 540.00
     
    Last edited by a moderator: Apr 11, 2021
    pshaw, Apr 11, 2021 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,818
    Likes Received:
    4,536
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Make the database do all the work.

    Look up some pagination tutorials and look at how limit and offset are setup.

    Once paytbl gets a few thousand records that page isn't going to load quickly if you don't.

    So, once your query only returns the records you want you don't have to do all the mod checks.
     
    sarahk, Apr 11, 2021 IP