Nvisible Posted January 7, 2012 Share Posted January 7, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/254531-php-page-break-after-4-rows/ Share on other sites More sharing options...
scootstah Posted January 7, 2012 Share Posted January 7, 2012 It basically works like this: $i = 1; while(blah) { if ($i % 4 == 0) { echo '<br />'; } $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/254531-php-page-break-after-4-rows/#findComment-1305205 Share on other sites More sharing options...
Nvisible Posted January 7, 2012 Author Share Posted January 7, 2012 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 But when printed the 5th coupon gets cut in half With the change it out puts this Quote Link to comment https://forums.phpfreaks.com/topic/254531-php-page-break-after-4-rows/#findComment-1305206 Share on other sites More sharing options...
scootstah Posted January 7, 2012 Share Posted January 7, 2012 My mistake, I thought you meant a line break. Take a look at this: http://www.w3.org/TR/CSS2/page.html Quote Link to comment https://forums.phpfreaks.com/topic/254531-php-page-break-after-4-rows/#findComment-1305213 Share on other sites More sharing options...
Nvisible Posted January 7, 2012 Author Share Posted January 7, 2012 Thanks that did the trick. I was banging my head on the wall thinking I needed a PHP Page break all I needed was a Print Media one. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/254531-php-page-break-after-4-rows/#findComment-1305331 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.