Help with pagination

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Cookiegal

Karen
Administrator
Malware Specialist Coordinator
Joined
Aug 27, 2003
Messages
121,302
You have to have at least 3 characters of text outside of a quote box.
 

Xsage

Dave
Joined
Jan 8, 2016
Messages
343
So if you want to total all results you can use something like this and do the same for each column, you just need to change the index in the 2nd parameter of the 'array_sum' method:

PHP:
echo " \r\n Total amtpaid:" . array_sum(array_column($results, 'amtpaid'));
If you only want to show the total for the items on the current page you can do something like this:

PHP:
$test = array_slice($results,((($pagenum + 1) * $BreakAT) - $BreakAT), (($pagenum + 1)* $BreakAT));
echo " \r\n Total amtdue:" . array_sum(array_column($test, 'amtdue'));
Now I'm not really an expert in php so I didn't know about this array_slice method until now, but you could potentially use it to make you code much cleaner as the array slice variable I have created here will create a new array from the original starting and ending at the index's of the the current page. So if you wanted, you could slice the array first and then just loop through the new array and display the results without the need to go through the 'for' loop or perform a modulus check etc. Its not an as fun or challenging way to do it but its probably much better:

PHP:
<?php
//Set at what record to break at 25 records per page
$BreakAT=25;
$pagenum = 0;
echo date('m/d/y');
echo "\r\nTotal rows: ".count($results)."\r\n";
echo " Page " . $pagenum . "\r\n";

?>

<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>due date</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 align=left>comment</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->amtpaid,2).'</td>
<td align=right class="currency">$'.number_format($row->amtdue,2).'</td>
<td>' . $row->duedate . '</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->comments . '</td>
</tr>';

}


echo '
<tr>
<td>' . array_sum(array_column($slice, 'amtpaid')) . '</td>';
//^ repeat and fill out html for other integer columns


?>
</table class="print">
<div class="breakhere"></div>
</center></div></body></html>
bear in mind for my example above I created a class for items of the table so rather than referencing the named index of the result, I'm referencing the properties of the objects (using ->tenant instead of ['tenant']) but you can change that to suit you, its only an example.
 
Last edited:

guitarzRus

Thread Starter
Joined
Jul 28, 2020
Messages
50
This just blew up. This is the code:
PHP:
<!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
error_reporting (E_ALL ^ E_NOTICE);
// Include config file
require_once "getprerentdb.php";
//MySqli Select Query
$results = $mysqli->query("SELECT * FROM payfile");//Print version
$results= $results->fetch_all(MYSQLI_ASSOC);
//Set at what record to break at 25 records per page
$BreakAT=25;
$pagenum = 0;
echo date('m/d/y');
echo "\r\nTotal rows: ".count($results)."\r\n";
echo " Page " . $pagenum . "\r\n";
?>

<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>due date</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 align=left>comment</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->amtpaid,2).'</td>
<td align=right class="currency">$'.number_format($row->amtdue,2).'</td>
<td>' . $row->duedate . '</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->comments . '</td>
</tr>'; //
} //
echo '
<tr>
<td>' . array_sum(array_column($slice, 'amtpaid')) . '</td>';
<td>' . array_sum(array_column($slice, 'amtdue')) . '</td>'; // line 69
<td>' . array_sum(array_column($slice, 'prevbal')) . '</td>';
<td>' . array_sum(array_column($slice, 'latechg')) . '</td>';
<td>' . array_sum(array_column($slice, 'secdep')) . '</td>';
<td>' . array_sum(array_column($slice, 'damage')) . '</td>';
<td>' . array_sum(array_column($slice, 'courtcost')) . '</td>';
<td>' . array_sum(array_column($slice, 'nsf')) . '</td>';
<td>' . array_sum(array_column($slice, 'hudpay')) . '</td>';
<td>' . array_sum(array_column($slice, 'paidsum')) . '</td>';
?>
</table class="print">
<div class="breakhere"></div>
</center></div></body></html>
and here is error?
unexpected '<', expecting end of file in C:\xa on line 69
 
Last edited by a moderator:

Xsage

Dave
Joined
Jan 8, 2016
Messages
343
On the lines like this:

<td>' . array_sum(array_column($slice, 'amtpaid')) . '</td>';

You need to get rid of the '; on the end of each but leave the last '
e.g:

PHP:
echo '
<tr>
<td>' . array_sum(array_column($slice, 'amtpaid')) . '</td>
<td>' . array_sum(array_column($slice, 'amtdue')) . '</td> // line 69
<td>' . array_sum(array_column($slice, 'prevbal')) . '</td>
<td>' . array_sum(array_column($slice, 'latechg')) . '</td>
<td>' . array_sum(array_column($slice, 'secdep')) . '</td>
<td>' . array_sum(array_column($slice, 'damage')) . '</td>
<td>' . array_sum(array_column($slice, 'courtcost')) . '</td>
<td>' . array_sum(array_column($slice, 'nsf')) . '</td>
<td>' . array_sum(array_column($slice, 'hudpay')) . '</td>
<td>' . array_sum(array_column($slice, 'paidsum')) . '</td>'
?>
</table class="print">
<div class="breakhere"></div>
</center></div></body></html>
Also I don't know if you have a class set up for the rows so I don't think referencing properties like I did will work for you like I explained in my last post:

PHP:
echo '
<tr>
<td>' . $row->tenant . '</td>
<td>' . $row->unit . '</td>
<td align=right class="currency">$'.number_format($row->amtpaid,2).'</td>
<td align=right class="currency">$'.number_format($row->amtdue,2).'</td>
<td>' . $row->duedate . '</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->comments . '</td>
</tr>';
These lines all need to change back to:

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

guitarzRus

Thread Starter
Joined
Jul 28, 2020
Messages
50
this is printed:
07/24/21 Total rows: 7 Page 0
Payment Report

. Rent Due Prev late sec court hud tenant Date
Tenant Unit Paid Due Date Bal chg dep damage cost nsf pay pay Paid Comment
$0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00
$0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00
$0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00
$0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00
$0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00
$0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00
$0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00
2785 3710 -25 10 25 55 0 0 0 2785
PHP:
<!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
error_reporting (E_ALL ^ E_NOTICE);
// Include config file
require_once "getprerentdb.php";
//MySqli Select Query
$results = $mysqli->query("SELECT * FROM payfile");//Print version
$results= $results->fetch_all(MYSQLI_ASSOC);
//Set at what record to break at 25 records per page
$BreakAT=25;
$pagenum = 0;
echo date('m/d/y');
echo "\r\nTotal rows: ".count($results)."\r\n";
echo " Page " . $pagenum . "\r\n";
?>

<div class="title"><h3>Payment Report</h3></div><br />
<table align="center" cellspacing=0 cellpadding=0 border=1>
<thead>
<tr>
<th colspan=2>.</th>
<th bgcolor="cyan" colspan=2>Rent</th>
<th>Due</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 bgcolor="cyan">tenant</th>
<th>Date</th>
<th></th>
<tr>
<th>Tenant</th>
<th>Unit</th>
<th bgcolor="cyan">Paid</th>
<th bgcolor="cyan">Due</th>
<th>Date</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 bgcolor="cyan">pay</th>
<th>Paid</th>
<th align=left>Comment</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->amtpaid,2).'</td>
<td align=right class="currency">$'.number_format($row->amtdue,2).'</td>
<td>' . $row->duedate . '</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->comments . '</td>
</tr>';
}
echo '
<tr>
<td bgcolor="cyan" align=right>' . array_sum(array_column($slice, 'amtpaid')) . '</td>
<td bgcolor="cyan" align=right>' . array_sum(array_column($slice, 'amtdue')) . '</td>
<td bgcolor="FF99FF" align=right>' . array_sum(array_column($slice, 'prevbal')) . '</td>
<td bgcolor="99FF99" align=right>' . array_sum(array_column($slice, 'latechg')) . '</td>
<td bgcolor="FF99FF" align=right>' . array_sum(array_column($slice, 'secdep')) . '</td>
<td bgcolor="99FF99" align=right>' . array_sum(array_column($slice, 'damage')) . '</td>
<td bgcolor="FF99FF" align=right>' . array_sum(array_column($slice, 'courtcost')) . '</td>
<td bgcolor="99FF99" align=right>' . array_sum(array_column($slice, 'nsf')) . '</td>
<td bgcolor="FF99FF" 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>
</center></div></body></html>
 

Xsage

Dave
Joined
Jan 8, 2016
Messages
343
re-read my last two posts about not referencing class properties. You need to use named array indexes because you don't have a class set up like I did during testing.

I'm here to help, not write your entire software for you.
 

guitarzRus

Thread Starter
Joined
Jul 28, 2020
Messages
50
re-read my last two posts about not referencing class properties. You need to use named array indexes because you don't have a class set up like I did during testing.

I'm here to help, not write your entire software for you.
thanks, you've been great. I got it worked out and I love the results. I more question
please. How do I show the results with $ and cents?
 
Last edited:

Xsage

Dave
Joined
Jan 8, 2016
Messages
343
you can use money_format instead of number_format like you have previously, and wrap the array_sums

I've included some different formats you can pick from, you can create your own format by reading up on the format string parameters of the money_format method.

PHP:
setlocale(LC_MONETARY,"en_US"); //setting this is important as it defines all money_formats as USD
echo '
<tr>
<td>' . money_format("%2i",array_sum(array_column($slice, 'amtpaid'))) . '</td>
<td>' . money_format("%2n",array_sum(array_column($slice, 'amtdue'))) . '</td>
<td>' . money_format("%!2n",array_sum(array_column($slice, 'prevbal'))) . '</td>'
Code:
"%2i"    =    USD 1,250.00
"%2n"    =    $1,250.00
"%!2n"    =    1,250.00
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Top