Hello, someone please help with code: I get the following Hello, someone please help with code: I get the following error:

Parse error: syntax error, unexpected 'endforeach' (T_ENDFOREACH) in
C:\xampp\htdocs\invoice\apdueprt.php on line 58
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
<head></head><body>
PHP Code:
<?php  
//Print version 
    //Set at what record to break at 25 records per page 
    
$BreakAT=25;  
    
$num=0
    
$pagenum 1;
     
$totdue=0
       
?>
HTML Code:
<div class="display print">
PHP Code:
<?php 
foreach($rows as $row): 
    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;
?>
HTML Code:
	<div class="title">Accounts Payable Report</div><br 
	<table align="center" cellspacing=0 cellpadding=0 border=1> 
	<thead> 
		<tr>
<thead> <th colspan=4></th>
<th bgcolor="#ccffff">date</th>
<th bgcolor="#ccffff">days</th>
<th bgcolor="#ccffff">amt</th>
<tr>
<th bgcolor="#ccffff">recur?</th>
<th bgcolor="#ccffff">acct#</th>
<th bgcolor="#ccffff">creditor</th>
<th bgcolor="#ccffff">purpose</th>
<th bgcolor="#ccffff">due</th>
<th bgcolor="#ccffff">late</th>
<th bgcolor="#ccffff">due</th>
		</tr> 
	</thead>
PHP Code:
<?php      
    $totdue 
+= $row['amtdue'];  
          echo 

    <tr> 
        <td>' 
$row['status'] . '</td> 
        <td>' 
$row['acctno'] . '</td> 
        <td>' 
$row['bname'] . '</td> 
        <td>' 
$row['purpose'] . '</td> 
        <td>' 
$row['duedate'] . '</td>           
         <td align=right class="currency">' 
. ($late 120 'pastdue' $row['dayslate']) . '</td>
         <td align=right class="currency">' 
number_format($row['amtdue'], 2'.''') . '</td>
     </tr>'

        
$num++;
[
B]endforeach;[/B]  
     echo 

    <tr> 
        <th scope="row" colspan="6">Grand Total:</th> 
        <td bgcolor="#FFD4D4" class="currency">' 
number_format($totdue2'.''') . '</td>
     </tr> 
</table>'
;
    }
   
?>
</div></body></html>