Jump to content

PHP Page Break After 4 Rows


Nvisible

Recommended Posts

So I have built a coupon component for Joomla which is working nicely.. However I am very green when it comes to Mysql and PHP more so the MySql part .. any way The user selects coupons adds them to a printing shopping cart so to speak and then prints the coupons.  However 4 coupons print fine to a page but the 5th coupon gets cut in half. I have tried spacing stuff out etc however since CSS is just a recommendation and there is not standard across so many browsers. It is just a mess. I did some googling and saw I can do a page break after so many rows however there is not alot of info on the structure so hoping some one can help.

Here is actually the complete code from the print page.

 

<?php
define('_JEXEC', '1');
include("../../configuration.php");
$config	=	new JConfig();
$conn	=	mysql_connect($config->host, $config->user, $config->password) or die("can not connect.");
mysql_select_db($config->db) or die("can not connect.");
$couponIds	=	implode(",", $_POST['selectCoupon']);
$coupon_footer_text	=	"";
$query	=	"select * from joc_other_settings limit 0,1 ";
$res	=	mysql_query($query );
$row	=	mysql_fetch_assoc($res);
$coupon_footer_text	=	$row['coupon_footer_text'];
$query	=	"select * from joc_logo where status='1' limit 0,1";
$res	=	mysql_query($query );
$logo	=	mysql_fetch_assoc($res);
$sql	=	"select * from joc_coupon c inner join joc_merchant m on c.mer_id=m.mer_id where c.cpn_id in (".$couponIds.")";
$res	=	mysql_query($sql);
if(mysql_num_rows($res) > 0)
{
while($row	=	mysql_fetch_assoc($res))
{
$address	=	$row['address']."<br>".$row['city'].", ".$row['state']."-".$row['zip'];
$logoToShow	=	($row['logo']!="")?"images/".$row['logo']:"images/company_logo/".$logo['logo'];
//////////// Begin Coupon /////////////////
?>
<head>
<link rel = "stylesheet" type="text/css" href="/components/com_coupon/print.css" >
</head>
<body>
<div id="box">
<div class="cpntitle"><?=$row['cpn_title']?></div>
<div class="cpndesc"><?=$row['cpn_desc']?></div>
<div class="boxlogo"><img height="75" width="175" src="../../<?=$logoToShow?>"></div>
<br />
<div class="cpnres">Sku: <?=$row['cpn_restriction']?></div>
<div class="cpnexp">Expires On: <?=date("m/d/Y", $row['cpn_expire'])?></div>
<img src="/images/cpimg/coupon_bottom.png">
</div>
<br />						
<?php 	
/////// End Coupon //////////
}
}
?>

<script type="text/javascript">
window.print();
</script>

 

I am pretty sure the page break goes in after

while($row	=	mysql_fetch_assoc($res))

But the actual structure is killing me. If some one can help me with this I would be great full could even shoot a few bucks over PayPal if you want.

 

Thanks

 

Link to comment
Share on other sites

Ok so I tried

 

	$i = 1;
while($row	=	mysql_fetch_assoc($res))
{
    if ($i % 4 == 0) {
        echo '<br />';
    }
    $i++;

 

And it completely messes it up.

With out the change the coupons lay out like this

YnkG8.png

But when printed the 5th coupon gets cut in half

With the change it out puts this

8yiIk.png

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.