SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    advice re. page break

    Hello, I'm hoping for help with page break in this code

    HTML Code:
    <html><head>
    <style>
        @page { size 8.5in 11in; margin: 2cm }
        div.page { page-break-after: always }
        </style>
    </head><body><center>
    <div class="page">
    PHP Code:
     <?php 
    error_reporting
    (E_ALL E_NOTICE);
    // error_reporting(0);
    mysql_connect('localhost','root','cookie');
    mysql_select_db('homedb') or die("Unable to select database");
    $query=" SELECT * FROM oocust WHERE payrec = 'P' AND pd = 'N' ORDER BY datepaid ASC";
    $result=mysql_query($query);
    $num=mysql_numrows($result);
    echo 
    date('m/d/y');

    // unsure re, the below

        
    echo "Page 1";
        
    ?>
    HTML Code:
    </div>
        <div class="page">
    PHP Code:
     <?php
        
    echo "Page 2";
      
    // 

    echo "<font size=+1><b><center> Accounts Payable Report</font></center><br />";
    ?>
    HTML Code:
    <table cellspacing=0 cellpadding=0 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 Code:
    <?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>
       </tr>'
    ;
        }     
        echo 
    '
          <tr>
            <th bgcolor="#ccffff" scope="row" colspan="6">Grand Total:</th>
              <td bgcolor="#FFD4D4" class="currency">'
    number_format($totdue2'.'''), '</td>
                </tr>
                 </table>'
    ;
                
    mysql_close();
               
    ?>
    HTML Code:
    </div></body></html>

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    And what is the problem you're encountering?

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    read my post man

  4. #4
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    724
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    I believe you are trying to make a print version... though you never said "what is the problem you're encountering" even though I did read your post.
    I found it easier to "display" two versions, one for screen, one for print. Not sure about detecting screen size in inches so I went with X number of records per-page. Adjust as needed. I didn't see where $late is defined, but hey, can't fix everything.
    PHP Code:
    <?php
    error_reporting
    (E_ALL E_NOTICE);
    // error_reporting(0);
    mysql_connect('localhost','root','cookie');
    mysql_select_db('homedb') or die("Unable to select database");

    $query="SELECT * FROM oocust WHERE payrec = 'P' AND pd = 'N' ORDER BY datepaid ASC";
    $result=mysql_query($query);
    $num=mysql_numrows($result);
    $rows = array();
    while (
    $rowa mysql_fetch_assoc($result)) {
        
    $rows[] = $rowa;
    }

    //echo "<pre>";
    //print_r($rows);
    //echo "</pre>"; 

    mysql_close();
    ?>
    <!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>
    <title>Report</title>
    <style type="text/css" media="screen">
    .display {
        width:800px;
        text-align:center;
        margin: 0 auto;
    }
    .title {
        font-size:1.1em;
        font-weight:bold;
    }
    .display th{
        background-color:#ccffff;
    }
    .print {
        display:none;
    }
    </style>

    <style type="text/css" media="print">
    .display {
        width:800px;
        text-align:center;
        margin: 0 auto;
    }
    .title {
        font-size:1.1em;
        font-weight:bold;
    }
    .display th{
        background-color:#ccffff;
    }
    .screen {
        display:none;
    }

    div.breakhere {
        page-break-before: always;
    }
    </style>

    </head>
    <body>
    <div class="display screen">
    <?php 
    echo date('m/d/y');
    ?>
    <div class="title">Accounts Payable Report</div><br />

    <table align="center" cellspacing=0 cellpadding=0 border=1>
    <thead>
        <tr>      
            <th colspan=4></th>
            <th>date</th>
            <th>days</th>
            <th>amt</th>
        <tr>
            <th>recur?</th>
            <th>acct#</th>
            <th>creditor</th>
            <th>purpose</th>
            <th>due</th>
            <th>late</th>
            <th>due</th>
        </tr>
    </thead>
    <?php
    foreach($rows as $row):
        
    $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>'
    ;
    endforeach;     
        echo 
    '
        <tr>
            <th scope="row" colspan="6">Grand Total:</th>
            <td bgcolor="#FFD4D4" class="currency">' 
    number_format($totdue2'.''') . '</td>
        </tr>
    </table>'
    ;
    ?> 
    </div>


    <?php   
        
    //Print version
        //Set at what record to break at
        //probably 25-30 records per page
        
    $BreakAT=25
        
    $num=0;
        
    $pagenum 1;
        
    $totdue=0;
    ?>     
    <div class="display print">
    <?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;
    ?>
        <div class="title">Accounts Payable Report</div><br />
        
        <table align="center" cellspacing=0 cellpadding=0 border=1>
        <thead>
            <tr>      
                <th colspan=4></th>
                <th>date</th>
                <th>days</th>
                <th>amt</th>
            <tr>
                <th>recur?</th>
                <th>acct#</th>
                <th>creditor</th>
                <th>purpose</th>
                <th>due</th>
                <th>late</th>
                <th>due</th>
            </tr>
        </thead>
    <?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++;
    endforeach;     
        echo 
    '
        <tr>
            <th scope="row" colspan="6">Grand Total:</th>
            <td bgcolor="#FFD4D4" class="currency">' 
    number_format($totdue2'.''') . '</td>
        </tr>
    </table>'
    ;
    ?> 
    </div>
    </body>
    </html>

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Drummin, thanks so much man. Your offering is fabulous, showing me better approach, better syntax & defining
    things I haven't grasped from other sites (I'll still have a lot of questions), speaking of which, I don't understand
    why the "endforeach" is "unexpected". I didn't see reference to "endforeach" in any site.

  6. #6
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    following is error derived from my current 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
    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"
            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) {  // 162
            $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>

  7. #7
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    724
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Seems silly asking, but you do have php section above doctype right?
    PHP Code:
    <?php
    error_reporting
    (E_ALL E_NOTICE);
    // error_reporting(0);
    mysql_connect('localhost','root','cookie');
    mysql_select_db('homedb') or die("Unable to select database");

    $query="SELECT * FROM oocust WHERE payrec = 'P' AND pd = 'N' ORDER BY datepaid ASC";
    $result=mysql_query($query);
    $num=mysql_numrows($result);
    $rows = array();
    while (
    $rowa mysql_fetch_assoc($result)) {
        
    $rows[] = $rowa;
    }

    //echo "<pre>";
    //print_r($rows);
    //echo "</pre>"; 

    mysql_close();
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •