keeping track of pages and mysql_num_rows
<p>Working off my previous <a href="http://stackoverflow.com/questions/9035131/printing-an-document-with-php-that-has-multiple-pages">question</a> I'm trying to figure out how to achieve what I'm after.
I have an order that gets made. When the time comes to print that order, if the order has more than 25 lines/rows i need to put up from line 26 and create a new page. My question is how would I write that? I was thinking with <code>mysql_num_rows</code> but how can I track that?</p>

<p>How would I break it down, say put rows 0-24 into <code>array1</code> then put <code>rows</code> 25-49 into <code>array2</code> and so on? Then put the different arrays into <code>while</code> loops?</p>

<p>Maybe put everything into an array, then split it up?</p>

<p>Here's what I have right now</p>

<pre><code>    &lt;?php

    if (isset($_POST['CheckBox'])){
    $CB = $_POST['CheckBox'];
    } else {echo 'Nothing Marked'; die;}
    /////////////////////////////////////////
    ?&gt;
    &lt;!DOCTYPE HTML&gt;
    &lt;html&gt;
    &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;style&gt;
    @media print{ @page{margin: 5%;} }
    body{
        background-color: #CCC;
        margin:0;
        padding:0;
        }
    #MainWrapper{
        margin:0 auto;
        width:675px;
        height:900px;
        background-color:#3CF;
        position:relative;
        }

    #OrderInfo{
        width:200px;
        height:50px;
        background-color:#6C6;
        float:left;
        font-family:Verdana, Geneva, sans-serif;
        font-size:9px;
    }
    #OrderInfoNotes{
        width:475px;
        height:50px;
        background-color:#6C6;
        float:right;
        font-family:Verdana, Geneva, sans-serif;
        font-size:9px;
    }
    #LineHeader{
        width:675px;
        background-color:#C90;
        float:left;
    }
    .OrderLines{
        font-family:Verdana, Geneva, sans-serif;
        font-size:9px;
        padding:0px;
    }

    .PBA{page-break-after: auto;}
    .bigbold{ font-weight:bold; font-size:14px;}
    .bigger{font-size:14px;}

    &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
    &lt;?php
    ///////////////////////////////////////////
    foreach ( $CB as $thekey =&gt; $Order_ID )
    {
$queryOrderHead = "SELECT * FROM Orders WHERE Order_ID = ".mysql_real_escape_string($Order_ID)."";
$queryOrderLines = "SELECT * FROM Order_LineDetails WHERE Order_LineDetails.Order_ID = ".mysql_real_escape_string($Order_ID)."";
    //////////////////////////////////////////
        if ($queryRunHead = mysql_query($queryOrderHead)){
    //////////////////////////////////////////
    // THIS IS THE HEADER OF THE ORDER ///////
    //////////////////////////////////////////
        while ($info_HEAD = mysql_fetch_array($queryRunHead))       
        {
        $OrderDate_HEAD = $info_HEAD['OrderDate'];
        $shippingservice_HEAD = $info_HEAD['shippingservice'];
        $OrderNotes_HEAD = $info_HEAD['OrderNotes'];
    ?&gt;                          
    &lt;div id="MainWrapper"&gt;                      
    &lt;!--START ORDERINFO INTO --&gt;
        &lt;div id="OrderInfo"&gt;
    Order ID:&lt;span class="bigbold"&gt;&lt;?php echo  ' '.$Order_ID; ?&gt;&lt;/span&gt;&lt;br&gt;
    &lt;?php echo 'SHIPPER: &lt;span class="bigbold"&gt;'.$shippingservice_HEAD.'&lt;/span&gt;'; ?&gt;&lt;br&gt;
    &lt;?php echo 'ORDER DATE: '.$OrderDate_HEAD; ?&gt;
        &lt;/div&gt;
        &lt;div id="OrderInfoNotes"&gt;
    &lt;?php echo 'NOTES: '.$OrderNotes_HEAD; ?&gt;&lt;/div&gt;
    &lt;!--END ORDERINFO INTO --&gt;
    &lt;hr&gt;&lt;br&gt;
        &lt;div id="LineHeader"&gt;
    &lt;table class="OrderLines"&gt;
    &lt;tr class="bigbold"&gt;
        &lt;td width="300"&gt;&lt;u&gt;Product Name:&lt;/u&gt;&lt;/td&gt;
        &lt;td width="90"&gt;&lt;u&gt;UPC Code:&lt;/u&gt;&lt;/td&gt;
        &lt;td width="50" align="right"&gt;&lt;u&gt;PID:&lt;/u&gt;&lt;/td&gt;
        &lt;td width="75" align="right"&gt;&lt;u&gt;QTY:&lt;/u&gt;&lt;/td&gt; 
        &lt;td width="160" align="right"&gt;&lt;u&gt;Packer:&lt;/u&gt;&lt;/td&gt;    
    &lt;/tr&gt;
    &lt;?php
    }
    /////////////////////////////////////////
    // THIS IS THE ORDER LINES //////////////
    /////////////////////////////////////////
            $queryRunLines = mysql_query($queryOrderLines);

            while ($info = mysql_fetch_array($queryRunLines))   
            {
                $ProductName_LINE = $info['ProductName'];
                $qty_LINE = $info['qty'];
                $Product_ID_LINE = $info['Product_ID'];
                $UPC_LINE = $info['UPC'];
    ?&gt;                          
    &lt;tr class="bigger"&gt;
        &lt;td&gt;&lt;?php echo $ProductName_LINE; ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $UPC_LINE; ?&gt;&lt;/td&gt;
        &lt;td align="right"&gt;&lt;?php echo $Product_ID_LINE; ?&gt;&lt;/td&gt;
        &lt;td align="right"&gt;&lt;?php echo $qty_LINE; ?&gt;&lt;/td&gt;    
        &lt;td&gt;&lt;/td&gt;    
    &lt;/tr&gt;&lt;tr&gt;
        &lt;td colspan="5"&gt;&lt;hr&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;?php                           
    }
    ///////////////////////////////////////////////////////////
    // END OF ORDER LINES /////////////////////////////////////     
    ///////////////////////////////////////////////////////////
                $numRows = 0;   
                $numRows = mysql_num_rows($queryRunLines);
                echo 'Total Rows ('.$numRows.')'
    ///////////////////////////////////////////////////////////
    ?&gt;&lt;tr&gt;
        &lt;td colspan="5" class="center"&gt;--- :END: ---&lt;/td&gt;
    &lt;/tr&gt;
    &lt;/table&gt;
    &lt;/div&gt;
    &lt;/div&gt;
    &lt;p class="PBA"/&gt;


    &lt;?php                       
    } else {
    echo mysql_error();         
    }
    }
    mysql_close($conn);
    ?&gt;
    &lt;/body&gt;
    &lt;/html&gt;
</code></pre>
