Tech Support Guy banner
Status
Not open for further replies.

Help with pagination

2K views 22 replies 3 participants last post by  Xsage 
#1 ·
Hi, got a prob. My code works great except that it only displays 1 line. Please advise.
----------------------------------------------------------------------------------------
the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">



<?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
//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 '';
$pagenum++; }

echo date('m/d/y');
echo " Page " . $pagenum;
?>
Payment Report

tenantunitrent paidrent duedue dateprev ballate chgsec depdamagecourt costnsfhud paytenant paydate paidcomment
' . $row['tenant'] . '' . $row['unit'] . '$'.number_format($row['amtpaid'],2).'$'.number_format($row['amtdue'],2).'' . $row['duedate'] . '$'.number_format($row['prevbal'],2).'$'.number_format($row['latechg'],2).'$'.number_format($row['secdep'],2).'$'.number_format($row['damage'],2).'$'.number_format($row['courtcost'],2).'$'.number_format($row['nsf'],2).'$'.number_format($row['hudpay'],2).'$'.number_format($row['paidsum'],2).'' . $row['datepaid'] . '' . $row['comments'] . '
Total Paid:' . number_format($totpaid, 2, '.', '') . '


<?php
$totpaid += $row['paidsum'];
echo '
';
$num++;
}
}
echo '
';

?>
 
See less See more
#2 ·
You seem to be missing a closing bracket on your if statement/it is in the wrong place. Below is a super simplified version of your code. In your code, the echo's that produce the records are where the uncommented "echo $num . "\r\n";" is. This code returns one record and it is record 0.
PHP:
<?php
$BreakAT=25;
$pagenum = 1;

for ($num = 0; $num <= 200; $num++) {

    if($num % $BreakAT == 0){
        if($num>0){
         $pagenum++;
         return;
        }
        echo $num . "\r\n";
    }
    //echo $num . "\r\n";
}
?>
If in the above code, you swap the comments so that the echo is one level higher and forms part of the "if($num % $BreakAT == 0)" statement, it returns 25 records there so I believe that is where you have gone wrong.

I'm not sure how you are going to handle the actual pagination though but you could do something like this:

PHP:
<?php
    $BreakAT=25;
    $pagenum = 0;

    for ($num = 0 + ($pagenum * 26); $num <= 200; $num++) {

        if($num % $BreakAT == 0){
            if($num>0){
                echo $num . "\r\n";
                $pagenum++;
                return;
            }
        }
        echo $num . "\r\n";
    }
?>
^ Every time you change page number it will only return the 25 results from the array for the current page
 
#3 ·
Is this what you're suggesting?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">



<?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

//Set at what record to break at 25 records per page

$BreakAT=25;
$pagenum = 0;

for ($num = 0 + ($pagenum * 26); $num <= 200; $num++) {

if($num % $BreakAT == 0){
if($num>0){
echo $num;
$pagenum++;
return;
}
}
echo $num;
}
$totpaid=0;
// ---------------------------------------
while($row = mysqli_fetch_array($results)) {
// ----------------------------------------
echo date('m/d/y');

?>
Payment Report
tenantunitrent paidrent duedue dateprev ballate chgsec depdamagecourt costnsfhud paytenant paydate paidcomment
' . $row['tenant'] . '' . $row['unit'] . '$'.number_format($row['amtpaid'],2).'$'.number_format($row['amtdue'],2).'' . $row['duedate'] . '$'.number_format($row['prevbal'],2).'$'.number_format($row['latechg'],2).'$'.number_format($row['secdep'],2).'$'.number_format($row['damage'],2).'$'.number_format($row['courtcost'],2).'$'.number_format($row['nsf'],2).'$'.number_format($row['hudpay'],2).'$'.number_format($row['paidsum'],2).'' . $row['datepaid'] . '' . $row['comments'] . '
Total Paid:' . number_format($totpaid, 2, '.', '') . '


<?php
$totpaid += $row['paidsum'];
echo ' ';
$num++;
}
}
echo '
';
?>
-------------------------------
displays: 012345678910111213141516171819202122232425
 
#4 ·
guitarzRus,

Please use the proper code tags when posting code as Xsage has done so that it displays properly. To do that click on the downward arrow beside the three dots in the menu bar above the reply box and select "Code" then in the next box select the coding language.
 
#5 · (Edited)
No not quite, this code should work for you. I reordered some stuff tho:

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

[CENTER]

<?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
    //Set at what record to break at 25 records per page
    $BreakAT=25;
    $pagenum = 0;
    $totpaid=0;
    echo date('m/d/y');
    echo "\r\nTotal rows: ".count($results)."\r\n";
    echo " Page " . $pagenum . "\r\n";

?>

Payment Report
[TABLE]

[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]comment[/TH]
[/TR]

<?php

     for($i = 0 + ($pagenum * $BreakAT); $i < count($results); $i++){

        //echo $i % $BreakAT;
        if($i % $BreakAT == 0)
        {
            if($i!=($pagenum * $BreakAT))
            {
                echo '</table class="print">';
                echo '';
                return;
            }
        }

        $row = $results[$i];

        $totpaid += $row->paidsum;
        echo "\r\n".($i)."\r\n";

        echo '
        [TR]
        [TD]' . $row['tenant'] . '[/TD]
        [TD]' . $row['unit'] . '[/TD]
        [TD]$'.number_format($row['amtpaid'],2).'[/TD]
        [TD]$'.number_format($row['amtdue'],2).'[/TD]
        [TD]' . $row['duedate'] . '[/TD]
        [TD]$'.number_format($row['prevbal'],2).'[/TD]
        [TD]$'.number_format($row['latechg'],2).'[/TD]
        [TD]$'.number_format($row['secdep'],2).'[/TD]
        [TD]$'.number_format($row['damage'],2).'[/TD]
        [TD]$'.number_format($row['courtcost'],2).'[/TD]
        [TD]$'.number_format($row['nsf'],2).'[/TD]
        [TD]$'.number_format($row['hudpay'],2).'[/TD]
        [TD]$'.number_format($row['paidsum'],2).'[/TD]
        [TD]' . $row['datepaid'] . '[/TD]
        [TD]' . $row['comments'] . '[/TD]
        [/TR]';

    }

    echo '
    [TR]
    [TH]Total Paid:[/TH]
    [TD]' . number_format($totpaid, 2, '.', '') . '[/TD]
    [/TR]
    [/TABLE]';
?>

[/CENTER]
Then all you would need are buttons or something that increases and decreases $pagenum to allow the user to change the page.
 
#6 ·
the code gives me this::
07/22/21
Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\property\paymentlist.php on line 19
Total rows: 1 Page 0
Payment Report

Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\property\paymentlist.php on line 47

tenantunitrent paidrent duedue dateprev ballate chgsec depdamagecourt costnsfhud paytenant paydate paid
comment​
Total Paid:0.00
 
#7 · (Edited)
Ah sorry, I somehow missed the part of the code you had to return the results as an array (because I don't have a database set up to test on so created my own array in code when testing):

You need to add something like:
$results= $results->fetch_all(MYSQLI_ASSOC);
straight after the mysqli query.

Or you can do a while loop like in your original post and assign to a variable like $rows in the same place and change $row = $results[$i]; to $row = $rows[$i];

reference: https://www.php.net/manual/en/mysqli-result.fetch-all.php

the count() method should work after that.
 
#8 ·
I must have misunderstood; my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">



<?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
//Set at what record to break at 25 records per page
$BreakAT=25;
$pagenum = 0;
$totpaid=0;
echo date('m/d/y');
echo "\r\nTotal rows: ".count($results)."\r\n"; // line19
echo " Page " . $pagenum . "\r\n";

?>

Payment Report
tenantunitrent paidrent duedue dateprev ballate chgsec depdamagecourt costnsfhud paytenant paydate paidcomment
' . $row['tenant'] . '' . $row['unit'] . '$'.number_format($row['amtpaid'],2).'$'.number_format($row['amtdue'],2).'' . $row['duedate'] . '$'.number_format($row['prevbal'],2).'$'.number_format($row['latechg'],2).'$'.number_format($row['secdep'],2).'$'.number_format($row['damage'],2).'$'.number_format($row['courtcost'],2).'$'.number_format($row['nsf'],2).'$'.number_format($row['hudpay'],2).'$'.number_format($row['paidsum'],2).'' . $row['datepaid'] . '' . $row['comments'] . '
Total Paid:' . number_format($totpaid, 2, '.', '') . '


<?php
for($i = 0 + ($pagenum * $BreakAT + 1); $i < count($results); $i++) { // line 47
// $row = $results[$i];
$row = $rows[$i];
$totpaid += $row->paidsum;
//echo "\r\n".$i."\r\n";
echo '
';

if($i % $BreakAT == 0)
{
if($i>0)
{
echo '</table class="print">';
echo '';
return;
}
}
}
echo '
';
?>
-------------------------------------------------
gets this:
Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\property\paymentlist4.php on line 19
Total rows: 1 Page 0
Payment Report

Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\property\paymentlist4.php on line 48
0
Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\property\paymentlist4.php on line 48
tenant unit rent paid rent due due date prev bal late chg sec dep damage court cost nsf hud pay tenant pay date paid comment
$0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00
Total Paid: 0.00
 
#9 ·
Yeah I think you did misunderstand. Basically in my code above, you need to convert $results from the mysqli response to an array before entering the 'for' loop.

As I said, I don't have a MySQL database set up for me to be able to test from so sorry in advance if these don't work, but try either of these:

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

[CENTER]

<?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;
    $totpaid=0;
    echo date('m/d/y');
    echo "\r\nTotal rows: ".count($results)."\r\n";
    echo " Page " . $pagenum . "\r\n";

?>

Payment Report
[TABLE]

[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]comment[/TH]
[/TR]

<?php

     for($i = 0 + ($pagenum * $BreakAT); $i < count($results); $i++){

        //echo $i % $BreakAT;
        if($i % $BreakAT == 0)
        {
            if($i!=($pagenum * $BreakAT))
            {
                echo '</table class="print">';
                echo '';
                return;
            }
        }

        $row = $results[$i];

        $totpaid += $row->paidsum;
        echo "\r\n".($i)."\r\n";

        echo '
        [TR]
        [TD]' . $row['tenant'] . '[/TD]
        [TD]' . $row['unit'] . '[/TD]
        [TD]$'.number_format($row['amtpaid'],2).'[/TD]
        [TD]$'.number_format($row['amtdue'],2).'[/TD]
        [TD]' . $row['duedate'] . '[/TD]
        [TD]$'.number_format($row['prevbal'],2).'[/TD]
        [TD]$'.number_format($row['latechg'],2).'[/TD]
        [TD]$'.number_format($row['secdep'],2).'[/TD]
        [TD]$'.number_format($row['damage'],2).'[/TD]
        [TD]$'.number_format($row['courtcost'],2).'[/TD]
        [TD]$'.number_format($row['nsf'],2).'[/TD]
        [TD]$'.number_format($row['hudpay'],2).'[/TD]
        [TD]$'.number_format($row['paidsum'],2).'[/TD]
        [TD]' . $row['datepaid'] . '[/TD]
        [TD]' . $row['comments'] . '[/TD]
        [/TR]';

    }

    echo '
    [TR]
    [TH]Total Paid:[/TH]
    [TD]' . number_format($totpaid, 2, '.', '') . '[/TD]
    [/TR]
    [/TABLE]';
?>

[/CENTER]
Or

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

[CENTER]

<?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
    $rows = $results->fetch_array(MYSQLI_BOTH);
    //Set at what record to break at 25 records per page
    $BreakAT=25;
    $pagenum = 0;
    $totpaid=0;
    echo date('m/d/y');
    echo "\r\nTotal rows: ".count($results)."\r\n";
    echo " Page " . $pagenum . "\r\n";

?>

Payment Report
[TABLE]

[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]comment[/TH]
[/TR]

<?php

     for($i = 0 + ($pagenum * $BreakAT); $i < count($results); $i++){

        //echo $i % $BreakAT;
        if($i % $BreakAT == 0)
        {
            if($i!=($pagenum * $BreakAT))
            {
                echo '</table class="print">';
                echo '';
                return;
            }
        }

        $row = $rows[$i];

        $totpaid += $row->paidsum;
        echo "\r\n".($i)."\r\n";

        echo '
        [TR]
        [TD]' . $row['tenant'] . '[/TD]
        [TD]' . $row['unit'] . '[/TD]
        [TD]$'.number_format($row['amtpaid'],2).'[/TD]
        [TD]$'.number_format($row['amtdue'],2).'[/TD]
        [TD]' . $row['duedate'] . '[/TD]
        [TD]$'.number_format($row['prevbal'],2).'[/TD]
        [TD]$'.number_format($row['latechg'],2).'[/TD]
        [TD]$'.number_format($row['secdep'],2).'[/TD]
        [TD]$'.number_format($row['damage'],2).'[/TD]
        [TD]$'.number_format($row['courtcost'],2).'[/TD]
        [TD]$'.number_format($row['nsf'],2).'[/TD]
        [TD]$'.number_format($row['hudpay'],2).'[/TD]
        [TD]$'.number_format($row['paidsum'],2).'[/TD]
        [TD]' . $row['datepaid'] . '[/TD]
        [TD]' . $row['comments'] . '[/TD]
        [/TR]';

    }

    echo '
    [TR]
    [TH]Total Paid:[/TH]
    [TD]' . number_format($totpaid, 2, '.', '') . '[/TD]
    [/TR]
    [/TABLE]';
?>

[/CENTER]
 
#10 ·
Man u r good. I've been working on this forever.
This is so close. The code:
-------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">



<?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;
$totpaid=0;
echo date('m/d/y');
echo "\r\nTotal rows: ".count($results)."\r\n";
echo " Page " . $pagenum . "\r\n";

?>

Payment Report
tenantunitrent paidrent duedue dateprev ballate chgsec depdamagecourt costnsfhud paytenant paydate paidcomment
' . $row['tenant'] . '' . $row['unit'] . '$'.number_format($row['amtpaid'],2).'$'.number_format($row['amtdue'],2).'' . $row['duedate'] . '$'.number_format($row['prevbal'],2).'$'.number_format($row['latechg'],2).'$'.number_format($row['secdep'],2).'$'.number_format($row['damage'],2).'$'.number_format($row['courtcost'],2).'$'.number_format($row['nsf'],2).'$'.number_format($row['hudpay'],2).'$'.number_format($row['paidsum'],2).'' . $row['datepaid'] . '' . $row['comments'] . '
Total Paid:' . number_format($totpaid, 2, '.', '') . '


<?php

for($i = 0 + ($pagenum * $BreakAT); $i < count($results); $i++){

//echo $i % $BreakAT;
if($i % $BreakAT == 0)
{
if($i!=($pagenum * $BreakAT))
{
echo '</table class="print">';
echo '';
return;
}
}

$row = $results[$i];

$totpaid += $row->paidsum;
echo "\r\n".($i)."\r\n";

echo '
';

}

echo '
';
?>

--------------------------------------------
the result:
07/23/21 Total rows: 7 Page 0
Payment Report

0 1 2 3 4 5 6
tenant unit rent paid rent due due date prev bal late chg sec dep damage court cost nsf hud pay tenant pay date paid comment
tenant1 apt1 $530.00 $530.00 2021-07-12 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $530.00 2021-07-10
tenant2 apt2 $540.00 $530.00 2021-07-12 $0.00 $10.00 $0.00 $0.00 $0.00 $0.00 $0.00 $540.00 2021-07-15 last time late
tenant3 apt3 $0.00 $530.00 2021-07-12 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 2021-07-12
tenan4 apt4 $575.00 $530.00 2021-07-12 $-45.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $575.00 2021-05-28 overpaid
tenant5 apt5 $0.00 $530.00 2021-07-12 $20.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 $0.00 0000-00-00
tenant6 apt6 $585.00 $530.00 2021-07-12 $0.00 $0.00 $0.00 $55.00 $0.00 $0.00 $0.00 $585.00 2021-07-20
tenant7 apt7 $555.00 $530.00 2021-07-12 $0.00 $0.00 $25.00 $0.00 $0.00 $0.00 $0.00 $555.00 2021-07-12
Total Paid: 0.00
 
#12 ·
I'm sorry, it's my first attempt at pagination and it's so cool. the only issue is
where is the "0 1 2 3 4 5 6" coming from and it doesn't total.
--------------------
07/23/21
Payment Report

0 1 2 3 4 5 6

tenantunitrent paidrent duedue dateprev ballate chgsec depdamagecourt costnsfhud paytenant paydate paid
comment​
tenant1apt1
$530.00​
$530.00​
2021-07-12
$0.00​
$0.00​
$0.00​
$0.00​
$0.00​
$0.00​
$0.00​
$530.00​
2021-07-10
tenant2apt2
$540.00​
$530.00​
2021-07-12
$0.00​
$10.00​
$0.00​
$0.00​
$0.00​
$0.00​
$0.00​
$540.00​
2021-07-15last time late
tenant3apt3
$0.00​
$530.00​
2021-07-12
$0.00​
$0.00​
$0.00​
$0.00​
$0.00​
$0.00​
$0.00​
$0.00​
2021-07-12
tenan4apt4
$575.00​
$530.00​
2021-07-12
$-45.00​
$0.00​
$0.00​
$0.00​
$0.00​
$0.00​
$0.00​
$575.00​
2021-05-28overpaid
tenant5apt5
$0.00​
$530.00​
2021-07-12
$20.00​
$0.00​
$0.00​
$0.00​
$0.00​
$0.00​
$0.00​
$0.00​
0000-00-00
tenant6apt6
$585.00​
$530.00​
2021-07-12
$0.00​
$0.00​
$0.00​
$55.00​
$0.00​
$0.00​
$0.00​
$585.00​
2021-07-20
tenant7apt7
$555.00​
$530.00​
2021-07-12
$0.00​
$0.00​
$25.00​
$0.00​
$0.00​
$0.00​
$0.00​
$555.00​
2021-07-12
Totals:
0.00​
0.00​
0.00​
0.00​
0.00​
0.00​
0.00​
0.00​
0.00​
0.00​
 
#13 ·
the 0 1 2 3 4 5 6 comes from the line echo "\r\n".($i)."\r\n"; I was using this for debugging, you can either get rid of it or comment it out.

As for the totals, in the following code change return; to break;:

PHP:
if($i!=($pagenum * $BreakAT))
{
    echo '</table class="print">';
    echo '';
    break; //here
}
 
#17 · (Edited)
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";

?>

Payment Report
[TABLE]

[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]comment[/TH]
[/TR]

<?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]$'.number_format($row->amtpaid,2).'[/TD]
[TD]$'.number_format($row->amtdue,2).'[/TD]
[TD]' . $row->duedate . '[/TD]
[TD]$'.number_format($row->prevbal,2).'[/TD]
[TD]$'.number_format($row->latechg,2).'[/TD]
[TD]$'.number_format($row->secdep,2).'[/TD]
[TD]$'.number_format($row->damage,2).'[/TD]
[TD]$'.number_format($row->courtcost,2).'[/TD]
[TD]$'.number_format($row->nsf,2).'[/TD]
[TD]$'.number_format($row->hudpay,2).'[/TD]
[TD]$'.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">

[/CENTER]
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.
 
#18 · (Edited by Moderator)
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">

[CENTER]

<?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";
?>

Payment Report
[TABLE]

[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]comment[/TH]
[/TR]

<?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]$'.number_format($row->amtpaid,2).'[/TD]
[TD]$'.number_format($row->amtdue,2).'[/TD]
[TD]' . $row->duedate . '[/TD]
[TD]$'.number_format($row->prevbal,2).'[/TD]
[TD]$'.number_format($row->latechg,2).'[/TD]
[TD]$'.number_format($row->secdep,2).'[/TD]
[TD]$'.number_format($row->damage,2).'[/TD]
[TD]$'.number_format($row->courtcost,2).'[/TD]
[TD]$'.number_format($row->nsf,2).'[/TD]
[TD]$'.number_format($row->hudpay,2).'[/TD]
[TD]$'.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">

[/CENTER]
and here is error?
unexpected '<', expecting end of file in C:\xa on line 69
 
#19 ·
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">

[/CENTER]
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]$'.number_format($row->amtpaid,2).'[/TD]
[TD]$'.number_format($row->amtdue,2).'[/TD]
[TD]' . $row->duedate . '[/TD]
[TD]$'.number_format($row->prevbal,2).'[/TD]
[TD]$'.number_format($row->latechg,2).'[/TD]
[TD]$'.number_format($row->secdep,2).'[/TD]
[TD]$'.number_format($row->damage,2).'[/TD]
[TD]$'.number_format($row->courtcost,2).'[/TD]
[TD]$'.number_format($row->nsf,2).'[/TD]
[TD]$'.number_format($row->hudpay,2).'[/TD]
[TD]$'.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]$'.number_format($row['amtpaid'],2).'[/TD]
        [TD]$'.number_format($row['amtdue'],2).'[/TD]
        [TD]' . $row['duedate'] . '[/TD]
        [TD]$'.number_format($row['prevbal'],2).'[/TD]
        [TD]$'.number_format($row['latechg'],2).'[/TD]
        [TD]$'.number_format($row['secdep'],2).'[/TD]
        [TD]$'.number_format($row['damage'],2).'[/TD]
        [TD]$'.number_format($row['courtcost'],2).'[/TD]
        [TD]$'.number_format($row['nsf'],2).'[/TD]
        [TD]$'.number_format($row['hudpay'],2).'[/TD]
        [TD]$'.number_format($row['paidsum'],2).'[/TD]
        [TD]' . $row['datepaid'] . '[/TD]
        [TD]' . $row['comments'] . '[/TD]
        [/TR]';
 
#20 ·
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">

[CENTER]

<?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";
?>

[B][SIZE=14]Payment Report[/SIZE][/B]

[TABLE]

[TR]
[TH].[/TH]
[TH]Rent[/TH]
[TH]Due[/TH]
[TH]Prev[/TH]
[TH]late[/TH]
[TH]sec[/TH]
[TH][/TH]
[TH]court[/TH]
[TH][/TH]
[TH]hud[/TH]
[TH]tenant[/TH]
[TH]Date[/TH]
[TH][/TH]
[TR]
[TH]Tenant[/TH]
[TH]Unit[/TH]
[TH]Paid[/TH]
[TH]Due[/TH]
[TH]Date[/TH]
[TH]Bal[/TH]
[TH]chg[/TH]
[TH]dep[/TH]
[TH]damage[/TH]
[TH]cost[/TH]
[TH]nsf[/TH]
[TH]pay[/TH]
[TH]pay[/TH]
[TH]Paid[/TH]
[TH]Comment[/TH]
[/TR]

<?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]$'.number_format($row->amtpaid,2).'[/TD]
[TD]$'.number_format($row->amtdue,2).'[/TD]
[TD]' . $row->duedate . '[/TD]
[TD]$'.number_format($row->prevbal,2).'[/TD]
[TD]$'.number_format($row->latechg,2).'[/TD]
[TD]$'.number_format($row->secdep,2).'[/TD]
[TD]$'.number_format($row->damage,2).'[/TD]
[TD]$'.number_format($row->courtcost,2).'[/TD]
[TD]$'.number_format($row->nsf,2).'[/TD]
[TD]$'.number_format($row->hudpay,2).'[/TD]
[TD]$'.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]
[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">

[/CENTER]
 
#21 ·
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.
 
#23 ·
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
Not open for further replies.
You have insufficient privileges to reply here.
Top