php code printing on 2 pages instead of 1 - php

I have build a POS system on php and facing one very funny issue. I can add upto 20 items on the sale memo and it gets stored in the db and we can retrieve it and print it, but whenever I print it, it always comes out in 2 pages instead of one even if there's one item and the rest of the value is null. Is there a way to force print on one page?
Here's the code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Print Invoice - Chara Motor Servicing</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.min.css" />
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="text-center">
<h3>Chara Motor Servicing</h3>
<h4>Address Line 1</h4>
<h4>Telephone: 000000000000</h4>
<h4>GSTIN: XXXXXXXXXXXXXXX</h4>
</div>
<hr>
<?php
include 'database_connection.php';
$data=$_GET['invoice_id'];
$user_id=$data;
$sql = "SELECT `name`, `phone`, `town`, `date`, `item1`, `item2`, `item3`, `item4`, `item5`, `item6`, `item7`, `item8`,`item9`, `item10`, `item11`, `item12`, `item13`, `item14`, `item15`, `item16`,`item17`, `item18`, `item19`, `item20`, `item21`, `item22`, `q1`, `q2`, `q3`, `q4`, `q5`, `q6`, `q7`, `q8`,`q9`, `q10`, `q11`, `q12`, `q13`, `q14`, `q15`, `q16`,`q17`, `q18`, `q19`, `q20`, `q21`, `q22`, `taxper`, `amt1`, `amt2`, `amt3`, `amt4`, `amt5`, `amt6`, `amt7`, `amt8`, `amt9`, `amt10`, `amt11`, `amt12`, `amt13`, `amt14`, `amt15`, `amt16`,`amt17`, `amt18`, `amt19`, `amt20`, `amt21`, `amt22`,`taxtotal`, `subtotal`, `status` FROM `sales` WHERE id=$user_id";
$result = $conn->query($sql);
while ($row = mysqli_fetch_array($result)):
?>
<div class="row">
<div class="col-xs-12 col-md-3 col-lg-3 pull-left">
<div class="panel panel-default height">
<div class="panel-heading">Invoiced To: </div>
<div class="panel-body">
<strong><?php echo $row['name']; ?></strong><br>
<?php echo $row['phone']; ?><br>
<?php echo $row['town']; ?><br>
<?php echo $row['date']; ?><br>
<strong>Invoice#: <?php echo $user_id; ?><br> </strong>
<strong><?php echo $row['status']; ?><br> </strong><br>
<button class="btn btn-primary hidden-print" onclick="myFunction()"><span class="glyphicon glyphicon-print" aria-hidden="true"></span> Print</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="text-center"><strong>Order Summary</strong></h3>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-condensed">
<thead>
<tr>
<td><strong>Item Name</strong></td>
<td class="text-center"><strong>Item Quantity</strong></td>
<td class="text-right"><strong>Total Price</strong></td>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $row['item1']; ?></td>
<td class="text-center"><?php echo $row['q1']; ?></td>
<td class="text-right"><?php echo $row['amt1']; ?></td>
</tr>
<tr>
<td><?php echo $row['item2']; ?></td>
<td class="text-center"><?php echo $row['q2']; ?></td>
<td class="text-right"><?php echo $row['amt2']; ?></td>
</tr>
<tr>
<td><?php echo $row['item3']; ?></td>
<td class="text-center"><?php echo $row['q3']; ?></td>
<td class="text-right"><?php echo $row['amt3']; ?></td>
</tr>
<tr>
<td><?php echo $row['item4']; ?></td>
<td class="text-center"><?php echo $row['q4']; ?></td>
<td class="text-right"><?php echo $row['amt4']; ?></td>
</tr>
<tr>
<td><?php echo $row['item5']; ?></td>
<td class="text-center"><?php echo $row['q5']; ?></td>
<td class="text-right"><?php echo $row['amt5']; ?></td>
</tr>
<tr>
<td><?php echo $row['item6']; ?></td>
<td class="text-center"><?php echo $row['q6']; ?></td>
<td class="text-right"><?php echo $row['amt6']; ?></td>
</tr>
<tr>
<td><?php echo $row['item7']; ?></td>
<td class="text-center"><?php echo $row['q7']; ?></td>
<td class="text-right"><?php echo $row['amt7']; ?></td>
</tr>
<tr>
<td><?php echo $row['item8']; ?></td>
<td class="text-center"><?php echo $row['q8']; ?></td>
<td class="text-right"><?php echo $row['amt8']; ?></td>
</tr>
<tr>
<td><?php echo $row['item9']; ?></td>
<td class="text-center"><?php echo $row['q9']; ?></td>
<td class="text-right"><?php echo $row['amt9']; ?></td>
</tr>
<tr>
<td><?php echo $row['item10']; ?></td>
<td class="text-center"><?php echo $row['q10']; ?></td>
<td class="text-right"><?php echo $row['amt10']; ?></td>
</tr>
<tr>
<td><?php echo $row['item11']; ?></td>
<td class="text-center"><?php echo $row['q11']; ?></td>
<td class="text-right"><?php echo $row['amt11']; ?></td>
</tr>
<tr>
<td><?php echo $row['item12']; ?></td>
<td class="text-center"><?php echo $row['q12']; ?></td>
<td class="text-right"><?php echo $row['amt12']; ?></td>
</tr>
<tr>
<td><?php echo $row['item13']; ?></td>
<td class="text-center"><?php echo $row['q13']; ?></td>
<td class="text-right"><?php echo $row['amt13']; ?></td>
</tr>
<tr>
<td><?php echo $row['item14']; ?></td>
<td class="text-center"><?php echo $row['q14']; ?></td>
<td class="text-right"><?php echo $row['amt14']; ?></td>
</tr>
<tr>
<td><?php echo $row['item15']; ?></td>
<td class="text-center"><?php echo $row['q15']; ?></td>
<td class="text-right"><?php echo $row['amt15']; ?></td>
</tr>
<tr>
<td><?php echo $row['item16']; ?></td>
<td class="text-center"><?php echo $row['q16']; ?></td>
<td class="text-right"><?php echo $row['amt16']; ?></td>
</tr>
<tr>
<td><?php echo $row['item17']; ?></td>
<td class="text-center"><?php echo $row['q17']; ?></td>
<td class="text-right"><?php echo $row['amt17']; ?></td>
</tr>
<tr>
<td><?php echo $row['item18']; ?></td>
<td class="text-center"><?php echo $row['q18']; ?></td>
<td class="text-right"><?php echo $row['amt18']; ?></td>
</tr>
<tr>
<td><?php echo $row['item19']; ?></td>
<td class="text-center"><?php echo $row['q19']; ?></td>
<td class="text-right"><?php echo $row['amt19']; ?></td>
</tr>
<tr>
<td><?php echo $row['item20']; ?></td>
<td class="text-center"><?php echo $row['q20']; ?></td>
<td class="text-right"><?php echo $row['amt20']; ?></td>
</tr>
<tr>
<td><?php echo $row['item21']; ?></td>
<td class="text-center"><?php echo $row['q21']; ?></td>
<td class="text-right"><?php echo $row['amt21']; ?></td>
</tr>
<tr>
<td><?php echo $row['item22']; ?></td>
<td class="text-center"><?php echo $row['q22']; ?></td>
<td class="text-right"><?php echo $row['amt22']; ?></td>
</tr>
<tr>
<td class="highrow"></td>
<td class="highrow"></td>
<td class="highrow text-center"><strong>GST/Tax (%)</strong></td>
<td class="highrow text-right"><?php echo $row['taxper']; ?></td>
</tr>
<tr>
<td class="emptyrow"></td>
<td class="emptyrow"></td>
<td class="emptyrow text-center"><strong>GST/Tax Amount</strong></td>
<td class="emptyrow text-right"><?php echo $row['taxtotal']; ?></td>
</tr>
<tr>
<td class="emptyrow"></td>
<td class="emptyrow text-center"><strong>SubTotal</strong></td>
<td class="emptyrow text-right"><strong><?php echo $row['subtotal']; ?></strong></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<script>
function myFunction() {
window.print();
}
</script>
<style>
.height {
min-height: 200px;
}
.icon {
font-size: 47px;
color: #5CB85C;
}
.iconbig {
font-size: 77px;
color: #5CB85C;
}
.table > tbody > tr > .emptyrow {
border-top: none;
}
.table > thead > tr > .emptyrow {
border-bottom: none;
}
.table > tbody > tr > .highrow {
border-top: 3px solid;
}
</style>
</div>
</body>
</html>

Related

Php mysqli list result's except those with *

I have this list, but i want my own IP adres to not show in this list,
how can i make an exception? like , if (Myip = in there) { dont show}
<?php
session_start();
include_once 'dbconnect.php';
?>
<?php include ('head.php') ; ?>
<?php include ('menu.php') ; ?>
<?php if (isset($_SESSION['usr_id'])) { ?>
<?
$user_list_result = $DBcon->query("select * from users order by username ASC limit 100");
$loggedTime=strtotime('-600 seconds'); //2 minutes
$session = $_SESSION['usr_name'];
$query = $DBcon->query("SELECT * FROM users WHERE username='$session'");
$userRow=$query->fetch_array();
if ($userRow['userlevel'] > 254) {
?>
<div class="container">
<div class="row">
<div class="col-md-12 col-sm-9 well">
<div class="panel panel-default panel-compact panel-wallet">
<div class="panel-body">
<center><h1>Userlist</h1></center>
<center>
<table >
<tr> <td width="20%"><b>ID </b></td>
<td width="20%"><b>Nickname </b></td>
<td width="20%"><b>Email </b></td>
<td width="20%"><b>Status </b></td>
<td width="20%"><b>Message </b></td>
<td width="20%"><b>Click </b></td>
<td width="20%"><b>clicks </b></td>
<td width="20%"><b>credits </b></td>
<td width="20%"><b>bitcoins </b></td>
<td width="20%"><b>dogecoins </b></td>
<td width="20%"><b>dashcoins </b></td>
<td width="20%"><b>refferals </b></td>
<td width="20%"><b>ip </b></td>
<td width="20%"><b>password </b></td>
<td width="20%"><b>edit </b></td> </tr>
<?php
while($UserlistRow = $user_list_result->fetch_array())
{
echo "
<tr>
<td>$UserlistRow[user_id]</td>
<td><a href=user_profile.php?user=$UserlistRow[username]>$UserlistRow[username]</a></td></center>";?>
<td><? echo $UserlistRow[email]; ?></td>
<td><?php if($UserlistRow['onlinedate']>'$loggedTime'){ echo "<img src='images/online.jpg'/>";}else{ echo "<img src='images/offline.jpg'/>";} ?> </td>
<td>Message</td>
<td>Click</td>
<td><?php echo $UserlistRow[clicks]; ?></td>
<td><?php echo$UserlistRow[credits]; ?></td>
<td><?php echo$UserlistRow[bitcoin]; ?></td>
<td><?php echo$UserlistRow[dogecoin]; ?></td>
<td><?php echo$UserlistRow[dashcoins]; ?></td>
<td><?php echo$UserlistRow[refferals]; ?></td>
<td><?php echo$UserlistRow[ip]; ?></td>
<td><?php echo$UserlistRow[password]; ?></td>
<td><a href=admin_user_edit.php?to=<? $userRow[username] ?> class=big>Edit</a></td>
</tr>
<?php } ?> </table>
</center>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<?php } else { include('login.php'); } ?>
<?php include ('footer.php') ; ?>
If you have a static ip then you can add a condition in the while loop as soon as it starts like,
if($ip_variable == "YOUR_IP"){
continue;
}
<?php
while($UserlistRow = $user_list_result->fetch_array())
{
if($UserlistRow[ip]!="ENTER YOUR IP HERE")
{
echo "
<tr>
<td>$UserlistRow[user_id]</td>
<td><a href=user_profile.php?user=$UserlistRow[username]>$UserlistRow[username]</a></td></center>";?>
<td><? echo $UserlistRow[email]; ?></td>
<td><?php if($UserlistRow['onlinedate']>'$loggedTime'){ echo "<img src='images/online.jpg'/>";}else{ echo "<img src='images/offline.jpg'/>";} ?> </td>
<td>Message</td>
<td>Click</td>
<td><?php echo $UserlistRow[clicks]; ?></td>
<td><?php echo$UserlistRow[credits]; ?></td>
<td><?php echo$UserlistRow[bitcoin]; ?></td>
<td><?php echo$UserlistRow[dogecoin]; ?></td>
<td><?php echo$UserlistRow[dashcoins]; ?></td>
<td><?php echo$UserlistRow[refferals]; ?></td>
<td><?php echo$UserlistRow[ip]; ?></td>
<td><?php echo$UserlistRow[password]; ?></td>
<td><a href=admin_user_edit.php?to=<? $userRow[username] ?> class=big>Edit</a></td>
</tr>
<?php }
}?>

why I cannot Displaying data from view in MySQL database?

I've a view to displaying some data from database to my php program, but the data cannot be displayed when I running it?
this is my view from phpmyadmin look like
(select `m`.`id_mutasi` AS `id_mutasi`,`m`.`tgl_mutasi` AS `tgl_mutasi`,`m`.`kode_barang` AS `kode_barang`,`a`.`nm_barang` AS `nm_barang`,`m`.`ruang_lama` AS `ruang_lama`,`m`.`ruang_baru` AS `ruang_baru`,`u`.`nm_unit` AS `unit_lama`,`m`.`unit_baru` AS `unit_baru`,`i`.`user` AS `user_lama`,`m`.`userbaru` AS `user_baru`,`m`.`jumlah` AS `jumlah`,`m`.`user_posting` AS `user_posting` from ((((((`simaset`.`mutasi` `m` join `simaset`.`inventarisasi` `i` on((`m`.`kode_inventarisasi_baru` = `i`.`kode_inventarisasi`))) join `simaset`.`aset` `a` on((`a`.`kode_barang` = `m`.`kode_barang`))) join `simaset`.`ruangan` `r` on((`r`.`kode_ruangan` = `m`.`ruang_lama`))) join `simaset`.`ruangan` `rb` on((`rb`.`kode_ruangan` = `i`.`kode_ruangan`))) join `simaset`.`unit_kerja` `u` on((`u`.`kode_unit` = `m`.`unit_lama`))) join `simaset`.`unit_kerja` `ub` on((`ub`.`kode_unit` = `i`.`kode_unit`))))
and this is my php code
<table id="table-example" class="table" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<!-- <th>NO</th> -->
<th>ID Mutasi</th>
<th>Tgl Mutasi</th>
<th>Kode Barang</th>
<th>Barang</th>
<th>Dept Lama</th>
<th>Jabatan Lama</th>
<th>Dept Baru</th>
<th>Jabatan Baru</th>
<!-- <th>User Baru</th> -->
<th>Jumlah</th>
<th>User Posting</th>
<!-- <th>User Posting</th> -->
<th>Aksi</th>
</tr>
</thead>
<tbody>
<!-- <?php $no = 1;?> -->
<?php do { ?>
<tr class=gradeX>
<!-- <td><center><?php echo $no++ ?></center></td> -->
<td><center>
<?php echo $row_rs_data['id_mutasi']; ?>
</center></td>
<td><?php echo $row_rs_data['tgl_mutasi']; ?></td>
<td ><?php echo $row_rs_data['kode_barang']; ?></td>
<td ><?php echo $row_rs_data['nm_barang']; ?></td>
<td ><?php echo $row_rs_data['ruanglama']; ?></td>
<td ><?php echo $row_rs_data['unitlama']; ?></td>
<td ><?php echo $row_rs_data['ruangbaru']; ?></td>
<td ><?php echo $row_rs_data['unitbaru']; ?></td>
<!-- <td ><?php echo $row_rs_data['userbaru']; ?></td> -->
<td ><center><?php echo $row_rs_data['jumlah']; ?></center></td>
<td ><?php echo $row_rs_data['user_posting']; ?></td>
<td ><img src="img/icons/packs/silk/16x16/cross.png" width="16" height="16" alt="Hapus" title="Hapus" /></td>
</tr>
<?php
echo "test";
} while ($row_rs_data = mysql_fetch_assoc($rs_data)); ?>
</tbody>
</table>
Replace your <tbody> block. Use while instead of do..while and mysqli instead of mysql mysql has been deprecated.
<tbody>
<?php while ($row_rs_data = mysql_fetch_assoc($rs_data)){ ?>
<tr class=gradeX>
<!-- <td><center><?php echo $no++ ?></center></td> -->
<td><center>
<?php echo $row_rs_data['id_mutasi']; ?>
</center></td>
<td><?php echo $row_rs_data['tgl_mutasi']; ?></td>
<td ><?php echo $row_rs_data['kode_barang']; ?></td>
<td ><?php echo $row_rs_data['nm_barang']; ?></td>
<td ><?php echo $row_rs_data['ruanglama']; ?></td>
<td ><?php echo $row_rs_data['unitlama']; ?></td>
<td ><?php echo $row_rs_data['ruangbaru']; ?></td>
<td ><?php echo $row_rs_data['unitbaru']; ?></td>
<!-- <td ><?php echo $row_rs_data['userbaru']; ?></td> -->
<td ><center><?php echo $row_rs_data['jumlah']; ?></center></td>
<td ><?php echo $row_rs_data['user_posting']; ?></td>
<td ><img src="img/icons/packs/silk/16x16/cross.png" width="16" height="16" alt="Hapus" title="Hapus" /></td>
</tr>
<?php
echo "test";
} ?>
</tbody>

Get Magento Order ID, Order Value and Coupon Code in success.phtml

We need to get Order ID, Order Value and Coupon Code from success.phtml.
We already have Google added to our success.phtml, and now we need to set up a new affiliate. We are not sure what $order_details and $adwords_saleamt do? Can we re-use them in any way?
Example
<?php
$order_details = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$adwords_saleamt = $order_details->subtotal;
?>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = xxxxxxxxxx;
var google_conversion_language = "xy";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "xxxxxxxxxxxx";
var google_conversion_value = 0.00;
if (<?php echo $adwords_saleamt; ?>) {
google_conversion_value = <?php echo $adwords_saleamt; ?>;
}
var google_conversion_currency = "EUR";
var google_remarketing_only = false;
/* ]]> */
</script>
You can try following
$order_details = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$adwords_saleamt = $order_details->subtotal; //subtotal without tax and shipping
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId(); //Order Id
$couponCode = $order_details->coupon_code; //Coupon code
Then use the values in your affiliate code.
Code there please, copy and paste in your file and then check, if any issue let me know...
echo $this->getLayout()->createBlock('checkout/cart_totals')->setTemplate('onepagecheckout/onepage/review/totals.phtml')->toHtml();
$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order_details = Mage::getModel('sales/order')->loadByIncrementId($order_id);
// Get shipping method
$shipping_method = $order_details->_data["shipping_description"];
// Get ship-to address information
$shipping_address_data = $order_details->getShippingAddress();
$session = Mage::getSingleton('core/session', array('name'=>'frontend'));
$card = $session->getGiftcard();
$cvv = $session->getGiftcardCvd();
$amount = $session->getGiftcardDeduct();
?>
<div class="inner_content">
<div class="inner-header-categories clearfix">
<h1><?php echo $this->__('Order Confirmation') ?></h1>
</div>
<div class="order_confirmation_div">
<h3><?php echo $this->__('Thank you for your order!') ?></h3>
<p>
<?php echo $this->__('Dear') ?> <?php echo $shipping_address_data['firstname']; ?>,<br>
<?php echo $this->__('Thank you for your order!') ?><br>
<?php if ($this->getCanViewOrder()) :?>
<p><?php echo $this->__('Your order id is: %s.', sprintf('%s', $this->escapeHtml($this->getViewOrderUrl()), $this->escapeHtml($this->getOrderId()))) ?></p>
<?php else :?>
<p><?php echo $this->__('Your order id is: %s.', $this->escapeHtml($this->getOrderId())) ?></p>
<?php endif;?>
</p>
<?php
$orderObj = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$orderItems = $orderObj->getAllItems();
?>
<h4><?php echo $this->__('Item Summary') ?></h4>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="order_ct_table">
<tr>
<th><?php echo $this->__('Product') ?></th>
<!--<th>Ship by</th>
<th>Delivers By</th>-->
<th><?php echo $this->__('Qty') ?></td>
<th class="no_border"><?php echo $this->__('UNIT PRICE') ?></th>
</tr>
<?php foreach($orderItems as $item)
{
?>
<tr>
<td class="porduct_dark_text"><div class="image_cart_in"><p><?php echo $item->getName();?></p></div></td>
<!--<td>18 August 2013</td>
<td>20 August 2013</td>-->
<td><?php echo round($item->getQtyOrdered(), 0);?></td>
<td class="no_border">$<?php echo number_format($item->getPrice(),2); ?></td>
</tr>
<?php }
?>
</table>
<h4><?php echo $this->__('Purchase Summary') ?>:</h4>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="order_ct_table_two">
<tr>
<td class="col_one_left"><?php echo $this->__('ITEM SUB TOTAL') ?> :</td>
<td class="no_border">$<?php echo number_format($orderValue = $orderObj->getSubtotal(),2);?></td>
</tr>
<?php if($orderObj->getDiscountAmount()!=0) { ?>
<tr>
<td class="col_one_left"><?php echo $this->__('Discount') ?> :</td>
<td class="no_border">$<?php echo number_format($orderValue = $orderObj->getDiscountAmount(),2);?></td>
</tr>
<?php } ?>
<tr>
<td class="col_one_left"><?php echo $orderObj->getShippingDescription(); ?>:</td>
<td class="no_border">$<?php echo number_format($orderSValue = $orderObj->getShippingAmount(),2); ?></td>
</tr>
<?php if(!empty($card)): ?>
<tr>
<td class="col_one_left"><?php echo $this->__('Giftcard ('.$card.') discount') ?>:</td>
<td class="no_border">$<?php echo number_format($amount,2); ?></td>
</tr>
<?php endif; ?>
<tr>
<td class="col_one_left"><?php echo $this->__('Tax') ?>:</td>
<?php
$GT = number_format($orderObj->getGrandTotal(),2);
$STA = number_format($orderSValue = $orderObj->getShippingAmount(),2);
$IST = number_format($orderValue = $orderObj->getSubtotal(),2);
$TAX = $IST+$STA;
$TTAX = $GT-$TAX;
?>
<td class="no_border">$<?php echo number_format($orderSValue = $orderObj->getTaxAmount(),2); ?></td>
</tr>
<tr>
<td class="col_one_left"><?php echo $this->__('Total') ?>:</td>
<td class="no_border">$<?php echo $GT;?></td>
</tr>
</table>
<ul class="billing_detail_confirm_ul_top"><li><h4><?php echo $this->__('Billing Address') ?></h4></li>
<li><h4><?php echo $this->__('Shipping Address') ?></h4></li></ul>
<ul class="billing_detail_confirm_ul">
<li>
<table border="0" cellspacing="0" cellpadding="0" style="border-right:none;">
<tr>
<td><?php echo $this->__('First Name') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['firstname']; ?></td>
</tr>
<tr>
<td><?php echo $this->__('Last Name') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['lastname'];?></td>
</tr>
<tr>
<td><?php echo $this->__('Company') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['company'];?></td>
</tr>
<tr>
<td><?php echo $this->__('Phone') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['telephone'];?></td>
</tr>
<tr>
<td><?php echo $this->__('Address') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['street'];?><br>
<?php echo $shipping_address_data['region']; ?>, <?php echo $shipping_address_data['postcode']; ?></td>
</tr>
<tr>
<td><?php echo $this->__('City') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['city'];?></td>
</tr>
<tr>
<td><?php echo $this->__('Country') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['country_id'];?></td>
</tr>
<tr>
<td><?php echo $this->__('State') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['region']; ?></td>
</tr>
<tr>
<td><?php echo $this->__('Zip') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['postcode']; ?></td>
</tr>
<tr>
<td><?php echo $this->__('Email') ?></td>
<td class="right_bold_text"><?php if($shipping_address_data['email']=='') { echo Mage::getSingleton('customer/session')->getCustomer()->getEmail(); } else { echo $shipping_address_data['email']; } ?></td>
</tr>
</table>
</li>
<li>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><?php echo $this->__('First Name') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['firstname']; ?></td>
</tr>
<tr>
<td><?php echo $this->__('Last Name') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['lastname'];?></td>
</tr>
<tr>
<td><?php echo $this->__('Company') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['company'];?></td>
</tr>
<tr>
<td><?php echo $this->__('Phone') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['telephone'];?></td>
</tr>
<tr>
<td><?php echo $this->__('Address') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['street'];?><br>
<?php echo $shipping_address_data['region']; ?>, <?php echo $shipping_address_data['postcode']; ?></td>
</tr>
<tr>
<td><?php echo $this->__('City') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['city'];?></td>
</tr>
<tr>
<td><?php echo $this->__('Country') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['country_id'];?></td>
</tr>
<tr>
<td><?php echo $this->__('State') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['region']; ?></td>
</tr>
<tr>
<td><?php echo $this->__('Zip') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['postcode']; ?></td>
</tr>
<tr>
<td><?php echo $this->__('Email') ?></td>
<td class="right_bold_text"><?php if($shipping_address_data['email']=='') { echo Mage::getSingleton('customer/session')->getCustomer()->getEmail(); } else { echo $shipping_address_data['email']; } ?></td>
</tr>
</table>
</li>
</ul>
<h3><td><?php echo $this->__('Thank you for shopping with us!') ?></td></h3>
<button class="proceed" style="margin-bottom:40px;" onclick="window.location='<?php echo $this->getUrl() ?>'"><?php echo $this->__('Return to Homepage') ?></button>
</div>
</div>

dompdf page break with codeigniter and foreach loop

I am using codeigniter and dompdf to generate a pdf document.
the document is generated with a foreach loop. each loop creates a few table rows. I want to have a pagebreak between the rows of each loop.
my relevent codeigniter view syntax is:
<table width=100%>
<?php foreach($summary as $summary){ ?>
<tr class="firstrow">
<td colspan="10">
<?php echo "<b>Customer</b>: <font color='blue'>".$summary->caccountname; ?>
<?php echo "</font> <b>Order Number</b>: <font color='blue'>".$summary->OrderNum; ?>
<?php echo "</font> <b>Sales rep</b>: <font color='blue'>".$summary->RepName; ?>
<?php echo "</font> <b>Due Date</b>: <font color='blue'>".substr($summary->DueDate,0,10); ?>
</td>
</tr>
<tr>
<td colspan="10"><hr>
</td>
</tr>
<tr>
<td colspan="10">
<table class="sortable" width="90%">
<tr><td ><b>Product</td><td ><b>Ordered</td><td ><b>Processed</td><td ><b>Outstanding</td><td ><b>Dispatched</td><td ><b>Available (incl FJ)</td><td ><b>Available FJ</td></tr>
<?php foreach($$linedetails as $linedetails){ ?>
<tr>
<td><?php echo $linedetails->Product; ?></td>
<td><?php echo $linedetails->cubicvolume; ?></td>
<td><?php echo $linedetails->Processed; ?></td>
<td><?php echo $linedetails->Outstanding; ?></td>
<td><?php echo $linedetails->Dispatched; ?></td>
<td><?php echo $linedetails->TotalVolume; ?></td>
<td><?php echo $linedetails->FJVolume; ?></td>
</tr>
<?php } ?>
</table>
</td>
</tr>
<?php } ?>
</table>
I have given the first tr a class of firstrow, I would like a page break to appear before this line every time.
As such I have applied the following style sheet in my page header:
<style>
#media print
{
.firstrow {page-break-before:always}
}
</style>
This doesnt work.
How can I acheive my desired result of placeing a page break before each loop firstrow TR?
Thanks as always
To make Pagebreak work with tr, write a line of css for tr
tr { page-break-inside:avoid; page-break-after:auto }
Try above code.
If not working, then add
table { page-break-inside:auto }
Try this, I am doing reports exactly same way
<?php
$nbsp5 = " ";
foreach($summary as $summary) { ?>
<table width="100%" style="page-break-after:always;">
<tr>
<td colspan="10">
<?php echo "<b>Customer</b>: <font color='blue'>".$summary->caccountname; ?>
<?php echo "</font>".$nbsp5 ." <b>Order Number</b>: <font color='blue'>".$summary->OrderNum; ?>
<?php echo "</font>".$nbsp5 ." <b>Sales rep</b>: <font color='blue'>".$summary->RepName; ?>
<?php echo "</font>".$nbsp5 ." <b>Due Date</b>: <font color='blue'>".substr($summary->DueDate,0,10); ?>
</td>
</tr>
<tr>
<td colspan="10"><hr></td>
</tr>
<tr>
<td colspan="10">
<table class="sortable" width="90%">
<tr>
<td><b>Product</b></td>
<td><b>Ordered</b></td>
<td><b>Processed</b></td>
<td><b>Outstanding</b></td>
<td><b>Dispatched</b></td>
<td><b>Available (incl FJ)</b></td>
<td><b>Available FJ</b></td>
</tr>
<?php foreach($$linedetails as $linedetails){ ?>
<tr>
<td><?php echo $linedetails->Product; ?></td>
<td><?php echo $linedetails->cubicvolume; ?></td>
<td><?php echo $linedetails->Processed; ?></td>
<td><?php echo $linedetails->Outstanding; ?></td>
<td><?php echo $linedetails->Dispatched; ?></td>
<td><?php echo $linedetails->TotalVolume; ?></td>
<td><?php echo $linedetails->FJVolume; ?></td>
</tr>
<?php } ?>
</table>
</td>
</tr>
</table>
<?php } ?>
(first <table> tag moved inside loop)
Please try this answer for both header and footer.

Weird table repeating when displaying mysql results

There's nothing wrong with the result itself.
The image should explain itself.
The table basicly is repeating the whole table for each results instead of displaying the results with multiple lines on one table, its doing 1 line on 1 table many times.
Here's the code that involves it-
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"id");
$f2=mysql_result($result,$i,"date");
$f3=mysql_result($result,$i,"agentclient");
$f4=mysql_result($result,$i,"propertydescription");
$f5=mysql_result($result,$i,"transactiontype");
$f5=mysql_result($result,$i,"applicabledocument");
$f5=mysql_result($result,$i,"received");
$f5=mysql_result($result,$i,"paid");
?>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr valign="bottom" bgcolor="#000000">
<td width="24"><span class="style1b"><strong>No.</strong></span></td>
<td width="105"><span class="style1b"><strong>Date</strong></span></td>
<td width="57"><span class="style1b"><strong>Agent/client</strong></span></td>
<td width="170"><span class="style1b"><strong>Property/Description</strong></span></td>
<td width="199"><span class="style1b"><strong>Transaction type </strong></span></td>
<td width="235"><span class="style1b"><strong>Applicable document </strong></span></td>
<td width="58"><span class="style1b"><strong>Received</strong></span></td>
<td width="58"><span class="style1b"><strong>Paid</strong></span></td>
</tr>
<tr valign="top" bgcolor="#FFFFFF">
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>
<td><?php echo $f3; ?></td>
<td><?php echo $f4; ?></td>
<td><?php echo $f5; ?></td>
<td><?php echo $f6; ?></td>
<td><?php echo $f7; ?></td>
<td><?php echo $f8; ?></td>
</tr>
</table>
<?php
$i++;
}
?>
There are lots of way to improve this code, but to fix your immediate problem, just take the header row out of the loop:
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr valign="bottom" bgcolor="#000000">
<td width="24"><span class="style1b"><strong>No.</strong></span></td>
<td width="105"><span class="style1b"><strong>Date</strong></span></td>
<td width="57"><span class="style1b"><strong>Agent/client</strong></span></td>
<td width="170"><span class="style1b"><strong>Property/Description</strong></span></td>
<td width="199"><span class="style1b"><strong>Transaction type </strong></span></td>
<td width="235"><span class="style1b"><strong>Applicable document </strong></span></td>
<td width="58"><span class="style1b"><strong>Received</strong></span></td>
<td width="58"><span class="style1b"><strong>Paid</strong></span></td>
</tr>
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"id");
$f2=mysql_result($result,$i,"date");
$f3=mysql_result($result,$i,"agentclient");
$f4=mysql_result($result,$i,"propertydescription");
$f5=mysql_result($result,$i,"transactiontype");
$f5=mysql_result($result,$i,"applicabledocument");
$f5=mysql_result($result,$i,"received");
$f5=mysql_result($result,$i,"paid");
?>
<tr valign="top" bgcolor="#FFFFFF">
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>
<td><?php echo $f3; ?></td>
<td><?php echo $f4; ?></td>
<td><?php echo $f5; ?></td>
<td><?php echo $f6; ?></td>
<td><?php echo $f7; ?></td>
<td><?php echo $f8; ?></td>
</tr>
<?php
$i++;
}
?>
</table>

Categories