• 0

print php report


Question

 Hi, Someone please tell me how to resolve this issue ? following is error derived from
my code which then follows:
 

Notice: Undefined variable: rows in C:\xampp\htdocs\invoice\apdueprnt.php on line 62
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\invoice\apdueprnt.php on line 62

 

<!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"
        lang="en"
        xml:lang="en"
    ><head>
     
    <meta
        http-equiv="Content-Type"
        content="text/html; charset=utf-8"
    />
     
    <meta
        http-equiv="Content-Language"
        content="en"
    />
     
    <meta
        name="viewport"
        content="width=device-width; height=device-height; initial-scale=1.0"
    />
     
    <link
        type="text/css"
        rel="stylesheet"
        href="print.css"
        media="print"
    />
     
    <title>
        Accounts Payable Demo
    </title>
     
    </head><body>
     
    <table class="accountsPayable">
        <caption>
            Accounts Payable Report
        </caption><thead>
            <tr>
                <th>recur?</th>
                <th>acct#</th>
                <th>creditor</th>
                <th>purpose</th>
                <th>due</th>
                <th>late</th>
                <th>due</th>
            </tr>
        </thead><tfoot>
            <tr>
                <td colspan="3">', date('m/d/y'), '</td>
                <td colspan="4" class="page"></td>
            </tr>
        </tfoot><tbody>
       
    <?php
       
    $totalDue = 0;
      // ******************************************** 
    foreach ($rows as $row) {   
        $totalDue += $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 class="currency">', ($row['dayslate'] > 120 ? 'pastdue' : $row['dayslate']), '</td>
                <td class="currency">', number_format($row['amtdue'], 2, '.', ''), '</td>
            </tr>';
    }
     
    echo '
            <tr class="grandTotal">
                <th scope="row" colspan="6">Grand Total:</th>
                <td class="currency">', number_format($totalDue, 2, '.', ''), '</td>
            </tr>';
    ?>
     
        </tbody>
    </table>
     
    </body></html>
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Exactly what it says is wrong with it is wrong with it. You're using a variable $rows in a foreach() and it references nothing at all.

 

Put data into $rows. Or check to see if $rows exists/has data before using the foreach(). sizeof() and count() should be fine for checking

if(isset($rows) && sizeof($rows) > 0){
    // your foreach() code
}
Link to comment
Share on other sites

  • 0

Indeed we're missing quite some code here, this is just the php code to print the data but there's no php code to get the data in the first place.

 

Edit: got leet(1337) post count yeah!

Link to comment
Share on other sites

  • 0

Hi, I'm trying to print this doc with heading at top of each printed page,
 page# at bottom of each page, thousands "," at "totdue" and without the
filename on each page. any help? Thanks

 

<html><head>
<style>
    @page { size 8.5in 11in; margin: 2cm }
    div.page { page-break-after: always }
    </style>
</head><body><center>
<div class="page">
 <?php
error_reporting(0);
mysql_connect('localhost','root','xxxxx');
mysql_select_db('homedb') or die("Unable to select database");
$query=" SELECT * FROM oocust WHERE payrec = 'R' AND pd = 'N' ORDER BY datepaid ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);
 
echo date('m/d/y');
echo "<font size=+1><b><center> Accounts Receivable Report</font></center></b></b><br />";
?>
<table cellspacing=0 cellpadding=2 border=1>
<thead>
<tr>      
<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>
<?php
while($row = mysql_fetch_array($result))
   {
$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> // ****perfect****
 
</tr>';
    }     
    echo '
            <tr>
       <th bgcolor="#ccffff" scope="row" colspan="6">Grand Total:</th>
       // <td bgcolor="#FFD4D4" class="currency">$', number_format($totdue, 2, '.', ''), '</td>

 <td align=right class="currency">$'. number_format('$totdue',2).'</td> // no thousands "," ***
 
  </tr>
    </table>';
    echo "Page 1";
    ?>
    </div>
    <div class="page">
    <?php
    echo "Page 2";

mysql_close();
?>
</body></html>
Link to comment
Share on other sites

  • 0

You didn't set a start value for totdue, make sure to add $totdue; before the loop to initialize it.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.