need help with pagination

propz

New Member
Hi, can someone advise me as to why I get this error? thanks

the 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><center>
<div class="display print">

<?php
//Open a new connection to the MySQL server
$link = mysqli_connect("localhost", "root", "", "homedb");

// Check connection
if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); }
echo date('m/d/y');

//MySqli Select Query
$sql = "select * FROM paytbl";
$result = mysqli_query($link,$sql);
if (!$result) {
printf("Error: %s\n", mysqli_error($link));
exit();
}else{
while($row = mysqli_fetch_array($result)){

//Set at what record to break at 25 records per page
$BreakAT=25;
$pagenum = 0;
echo date('m/d/y');

?>
<b>
<div class="title"><h3>Payment Report</h3></div><br />
<table align="center" cellspacing=5 cellpadding=5 border=2>
<thead>
<tr>
<th colspan=2> </th>
<th bgcolor="cyan" colspan=2>Rent</th>
<th bgcolor="99FF99">Prev</th>
<th bgcolor="FF99FF">late</th>
<th bgcolor="99FF99">sec</th>
<th></th>
<th bgcolor="99FF99">court</th>
<th></th>
<th bgcolor="99FF99">hud</th>
<th>Date</th>
<th colspan=2></th>
<tr>
<th>Tenant</th>
<th>Unit</th>
<th bgcolor="cyan">Due</th>
<th bgcolor="cyan">Paid</th>
<th bgcolor="99FF99">Bal</th>
<th bgcolor="FF99FF">chg</th>
<th bgcolor="99FF99">dep</th>
<th bgcolor="FF99FF">damage</th>
<th bgcolor="99FF99">cost</th>
<th bgcolor="FF99FF">nsf</th>
<th bgcolor="99FF99">pay</th>
<th>Paid</th>
<th bgcolor="cyan">Paidsum</th>
<th>Comments</th>
</tr>
</thead>

<?php
$slice= array_slice($results,((($pagenum + 1) * $BreakAT) - $BreakAT), (($pagenum + 1)* $BreakAT));
foreach($slice as $row){

echo '
<tr>
<td>' . $row['tenant'] . '</td>
<td>' . $row['unit'] . '</td>
<td align=right class="currency">$'.number_format($row['amtdue'],2).'</td>
<td align=right class="currency">$'.number_format($row['amtpaid'],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>' . $row['datepaid'] . '</td>
<td align=right class="currency">$'.number_format($row['paidsum'],2).'</td>
<td>' . $row['comments'] . '</td>
</tr>';
}

echo '
<tr>
<td colspan=2></td>
<td bgcolor="cyan" align=right>' . array_sum(array_column($slice, 'amtdue')) . '</td>
<td bgcolor="cyan" align=right>' . array_sum(array_column($slice, 'amtpaid')) . '</td>
<td bgcolor="99FF99" align=right>' . array_sum(array_column($slice, 'prevbal')) . '</td>
<td bgcolor="FF99FF" align=right>' . array_sum(array_column($slice, 'latechg')) . '</td>
<td bgcolor="99FF99" align=right>' . array_sum(array_column($slice, 'secdep')) . '</td>
<td bgcolor="FF99FF" align=right>' . array_sum(array_column($slice, 'damage')) . '</td>
<td bgcolor="99FF99" align=right>' . array_sum(array_column($slice, 'courtcost')) . '</td>
<td bgcolor="FF99FF" align=right>' . array_sum(array_column($slice, 'nsf')) . '</td>
<td bgcolor="99FF99" align=right>' . array_sum(array_column($slice, 'hudpay')) . '</td>
<td bgcolor="cyan" align=right>' . array_sum(array_column($slice, 'paidsum')) . '</td>'
} // ************* line 100 ***********************************
?>
</table class="print">
<div class="breakhere"></div>
</b></center></div></body></html>

result:
Parse error: syntax error, unexpected '}', expecting ';' or ','
in C:\xampp\htdocs\property\paymentlist.php on line 100
 

Cromewell

Administrator
Staff member
You are missing a ; after the echo that ends on line 99.

edit: I think you are also missing a closing } somewhere. Pretty sure the one on line 100 lines up with the while on line 22.
 
Last edited:

propz

New Member
I truncated the code and made the suggested changes and this took place?

<!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><center>
<div class="display print">

<?php
//Open a new connection to the MySQL server
$link = mysqli_connect("localhost", "root", "", "homedb");

// Check connection
if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); }
echo date('m/d/y');

//MySqli Select Query
$sql = "select * FROM paytbl";
$result = mysqli_query($link,$sql);
if (!$result) {
printf("Error: %s\n", mysqli_error($link));
exit();
}else{
while($row = mysqli_fetch_array($result)){

//Set at what record to break at 25 records per page
$BreakAT=25;
$pagenum = 0;
echo date('m/d/y');

?>
<b>
<div class="title"><h3>Payment Report</h3></div><br />
<table align="center" cellspacing=5 cellpadding=5 border=2>
<thead>
<tr>
<th colspan=2> </th>
<th bgcolor="cyan" colspan=2>Rent</th>
<th bgcolor="99FF99">Prev</th>
<th bgcolor="FF99FF">late</th>
<th bgcolor="99FF99">sec</th>
<th></th>
<th bgcolor="99FF99">court</th>
<th></th>
<th bgcolor="99FF99">hud</th>
<th>Date</th>
<th colspan=2></th>
<tr>
<th>Tenant</th>
<th>Unit</th>
<th bgcolor="cyan">Due</th>
<th bgcolor="cyan">Paid</th>
<th bgcolor="99FF99">pay</th>
<th>Paid</th>
<th bgcolor="cyan">Paidsum</th>
<th>Comments</th>
</tr>
</thead>

<?php
$slice= array_slice($results,((($pagenum + 1) * $BreakAT) - $BreakAT), (($pagenum + 1)* $BreakAT));
foreach($slice as $row){

echo '
<tr>
<td>' . $row['tenant'] . '</td>
<td>' . $row['unit'] . '</td>
<td align=right class="currency">$'.number_format($row['amtdue'],2).'</td>
<td align=right class="currency">$'.number_format($row['amtpaid'],2).'</td>
<td align=right class="currency">$'.number_format($row['hudpay'],2).'</td>
<td>' . $row['datepaid'] . '</td>
<td align=right class="currency">$'.number_format($row['paidsum'],2).'</td>
<td>' . $row['comments'] . '</td>
</tr>';
}

echo '
<tr>
<td colspan=2></td>
<td bgcolor="cyan" align=right>' . array_sum(array_column($slice, 'amtdue')) . '</td>
<td bgcolor="cyan" align=right>' . array_sum(array_column($slice, 'amtpaid')) . '</td>
<td bgcolor="99FF99" align=right>' . array_sum(array_column($slice, 'hudpay')) . '</td>
<td bgcolor="cyan" align=right>' . array_sum(array_column($slice, 'paidsum')) . '</td>';
} ?>
</table class="print">
<div class="breakhere"></div>
</b></center></div></body></html> // line 86
===============
unexpected EOF on line 86
 

Cromewell

Administrator
Staff member
The second part of my reply still applies. On line 21 your else is opening but is never closed, there is a closing } missing. The one on line 83 closes the while loop on line 22, and you just need a second one there.

What editor are you using? Using one that has syntax highlighting, matches brackets for you and does proper indentation will help a lot in finding these kinds of errors.
 

Cromewell

Administrator
Staff member
Notepad++ is fine, it will highlight matching brackets for you. If you do not already have it, you can get syntax checking by adding NppExec as a plugin and giving it a command like
"<whatever your php path is>\php.exe" -l $(FULL_CURRENT_PATH)

If you move your cursor over the closing } on line 83, or any other { or } for that matter, you should see the matching one bolded or colored which is very helpful for making sure you have them all matched up.

The other thing that helps is added 1 level of indention every time you open a { and remove 1 level of indentation whenever you close one. That way if your code does not unindent all the way back at the end of the file you know you have missed a closing } somewhere.
 
Top