Page 1 of 1

Page break

Posted: Mon Mar 15, 2010 8:09 am
by bobcon
As a update to the below: Basically the print version of the page results needs to be limited to 3 results/rows per page

Please can someone help?

I am pretty new to php and what I would like to do is insert a page break after 3 rows on the code below:

Any help would be much appreciated

Code: Select all

 
<?php 
 
 
  $sortBy = $cgi->getValue ( "SortBy" );
  $page = intval ( $cgi->getValue ( "page" ) );
  
  if ( ! $sortBy )
  {
    $sortBy = "id";
  }
 
     $rows = $sql->execute ( "
     
    SELECT *
      
    FROM
      " . $property_table . " 
     p 
 
 WHERE propertystatus ='5' 
    " , 
    SQL_RETURN_ASSOC );
 
  $total_results = sizeof ( $rows);
  
 
  
  if ( $total_results )
  {
 
 
    ?>
 
<br /> 
 
<?php
  
    for ( $i = 0; $i < $total_results; ++$i )
    {
      $row              = $rows [ $i ];
      $id               = $row [ "property_id" ];
      $propertyroption  = $row [ "propertyoption" ];
      $propertyref      = $row [ "propertyref" ];
      $propertyphoto1   = $row [ "propertyphoto1" ];
      $propertyaddress  = $row [ "propertyaddress" ];
      $propertytype     = $row [ "propertytype" ];
      $propertylocation = $row [ "propertylocation" ];
      $longdescription = $row [ "longdescription" ];
      $propertyprice    = number_format ( $row [ 'propertyprice' ], PRICE_FORMAT ); 
      ?>
  
<table width="100%" cellspacing="1" cellpadding="5" bgcolor="#CCCCCC" align="center" border="0">
<tr valign="middle">
<td bgcolor="#F3F3F3" valign="middle" align="center" width="125"><p><b>Photo</b></p></td>
<td bgcolor="#F3F3F3" valign="middle" align="left" width="125"><p><b>Property Details</b></p></td>
<td bgcolor="#F3F3F3" valign="middle" align="left" width="500"><p><b>Property Description</b></p></td>
<td bgcolor="#F3F3F3" valign="middle" align="center"><p><b>Price P/A</b></p></td>
</tr>
<tr valign="middle">
<td bgcolor="#FFFFFF" valign="middle" align="center"><?php if ($propertyphoto1) {print "<img src=\"$ImageURL$propertyphoto1\" width=\"125\" height=\"85\">"; }?></td>
<td width="125" bgcolor="#FFFFFF" valign="middle" align="top">
<p><b>Property Ref:</b> <?php echo $cgi->htmlEncode ( $propertyref ); ?><br />
<b>Property Type:</b> <?php echo $cgi->htmlEncode ( $propertytype ); ?><br />
<b>Address:</b> <?php echo $cgi->htmlEncode ( $propertyaddress ); ?>, <?php echo $cgi->htmlEncode ( $propertylocation ); ?></p></td>
<td width="500" bgcolor="#FFFFFF" valign="middle" align="left"><p><?php echo $cgi->htmlEncode ( $longdescription ); ?></p></td>
<td bgcolor="#FFFFFF" valign="middle" align="center"><p>
<?php echo CURRENCY; ?><?php echo $cgi->htmlEncode ( $propertyprice ); ?></p></td>
</tr>
 </table>
<br />
<?php
    }
  }
 
?>
 
 

Re: Page break

Posted: Tue Mar 16, 2010 8:08 pm
by Sofw_Arch_Dev
As you get better at PHP your code will get cleaner and more logically organized, but that's not important right now. Working with your existing structure you could simply put a condition into the code near the end of the loop.

Code: Select all

 
if( ( ( $i+1) % 3 ) == 0 ) {
      // put your page break stuff here.
}
 
I'm not sure what you mean by a page break but the above code will enter the page break section after EVERY 3.