how to create a second a4 page in codeigniter? - php

I am writing a simple invoice web tool.
Invoices should be in the size of A4.
My Controller:
$this->load->view('static/print_header');
$this->load->view('static/print_invoice', $data);
$this->load->view('static/print_footer');
$data are my invoice items positions like:
HEADER
Pos ---- Item ---- Price
1 item1 10€
2 item2 10€
3 itemitem 20€
FOOTER
If I have to many items (or they have to much text) items will go inside Footer Section and I can't create a right A4 page.
How can I change my Controller to get something like this:
For eg.: 2 Pages if to many items:
Page1:
HEADER
Pos ---- Item ---- Price
1 item1 10€
2 item2 10€
3 itemitem 20€
FOOTER
Page2:
HEADER
Pos ---- Item ---- Price
4 item3 10€
5 itemitemitem 40€
6 itemitem1234 20€
FOOTER
EDIT: Add invoice code
<div id="content">
<div><span style="font-size: x-large;"><strong>Invoice</strong></span></div>
<hr />
<div>
<table style="width: 100%" id="invoice_task_list">
<tr style="background:#eee;">
<td style="width:8%;"><b>Pos.</b></td>
<td style="width:47%;"><b>Description</b></td>
<td style="width:15%;"><b>Date</b></td>
<td style="width:20%;"><b>Hours</b></td>
<td style="width:10%;"><b>Sum</b></td>
<?php
$pos = 1;
foreach( $items as $it): ?>
<tr>
<td style="width:8%;"><?php echo $pos; ?></td>
<td style="width:47%;"><?php echo $it->invoice_item_text; ?></td>
<td style="width:15%;">
<?php if ($it->invoice_item_type == 3) {$date = date('M Y', strtotime($it->invoice_item_date)); } else { $date = date('d.m.Y', strtotime($it->invoice_item_date)); } ?>
<?php echo $date; ?>
</td>
<td style="width:20%;"><?php if ($it->invoice_item_time != '0') { if ($it->invoice_item_type == 1 or $it->invoice_item_type == 2) echo gmdate('H:i', $it->invoice_item_time);}; ?></td>
<td style="width:10%;"><?php echo number_format($it->invoice_item_sum, 2, ',', ' '); ?> €</td>
</tr>
<?php $pos++; ?>
<?php endforeach; ?>
<tr>
<td colspan="3"> </td>
<td> Total (netto): </td>
<?php $netto = $sum['invoice_item_sum']; ?>
<td style="text-align: right;"><span class="currency"><?php echo number_format($netto, 2, ',', ' ') ?> €</span></td>
</tr>
<tr>
<td colspan="3"> </td>
<td> Tax 20.00% </td>
<td style="text-align: right;"><span class="currency">
<?php $tmptax = (($sum['invoice_item_sum'])/100)*$invoice['invoice_tax']; ?>
<?php echo number_format($tmptax, 2, ',', ' ')?> €</span></td>
</tr>
<tr>
<td colspan="3"> </td>
<td> Total (brutto): </td>
<td style="text-align: right;"><span class="currency" style="text-decoration: underline; font-weight: bold;">
<?php $total = ($sum['invoice_item_sum'])+((($sum['invoice_item_sum'])/100)*$invoice['invoice_tax']); ?>
<?php echo number_format($total, 2, ',', ' ')?> €</span></td>
</tr>
</table>
</div>
</div>

This sounds like more of a css issue than a php/codeigniter issue.
Make sure you have a clearfix after your invoice container:
.clearfix {
float:none;
clear:both;
}
And that you have the correct page break settings for printing.
#media print {
.footer {page-break-after: always;}
}
Note that an A4 piece of paper is 2480 x 3508 pixels, so make sure you CSS is adjusted for that!
Edit (After Clarifications):
There are a couple of different ways to determine whether or not your need to additional header/footer for another page. I'm going to go with what I think would be the simplest. If your rows are uniform in that (20) rows make up a whole page, then you can do a simple check and loop your views.
//Note that you'll have to specify only putting 20 records here
if ($rows->num_rows() > 20) {
for ($i = 0; $i < $rows->num_rows(); $i += 20) {
$data['start'] = $i;
$data['end' = $i + 20;
$this->load->view('static/print_header');
$this->load->view('static/print_invoice', $data);
$this->load->view('static/print_footer');
}
}

If trying to add header and footer on all pages try adding <thead> and <tfoot> elements. On using this it displays the top and bottom contents on all the pages Or you can use the css styles-
<thead>
// your header content
</thead>
<tfoot>
//your footer content
</tfoot>
CSS
#header {
display: table-header-group;
}
#footer {
display: table-footer-group;
}

Related

I want to style Opencart checkout grand total

I am trying to style my Opencart theme, but I have a problem.
I want to style the grand total result on the checkout page. The problem is I can't style only the grand total result because automatic changes the Sub-total style.
For example I want to make the grand total result BOLD
The code is this:
<tfoot>
<?php foreach ($totals as $total) { ?>
<tr>
<td colspan="2" class="price"><b><?php echo $total['title']; ?>:</b></td>
<td colspan="2" class="grandtotal-style-css"><?php echo $total['text']; ?></td>
</tr>
<?php } ?>
</tfoot>
I found this but is for old Opencart and is not working.
Link is here (opencart.com)
http://forum.opencart.com/viewtopic.php?f=6&t=1986#p9366
Each type of totals row has a unique code (total, sub_total, shipping etc.), so personally, I would change it to something like this:
<tfoot>
<?php foreach ($totals as $total) { ?>
<tr>
<td colspan="2" class="price"><b><?php echo $total['title']; ?>:</b></td>
<td colspan="2" class="totals-<?php echo $total['code']; ?>"><?php echo $total['text']; ?></td>
</tr>
<?php } ?>
</tfoot>
Then change your css class from .grandtotal-style-css to .totals-total
Can you not use the :last-of-type pseudo-element?
.grandtotal-style-css:last-of-type {
font-weight: bold;
}
You have to check for the code of the totals and add styles only for the total (or grandtotal?) one:
<?php foreach ($totals as $total) { ?>
<tr>
<?php if ($total['code'] == 'total') { /* change for 'grandtotal' if needed */ ?>
<td colspan="2" class="price"><b><?php echo $total['title']; ?>:</b></td>
<td colspan="2" class="grandtotal-style-css"><?php echo $total['text']; ?></td>
<?php } else {
<td colspan="2" class="price"><?php echo $total['title']; ?>:</td>
<td colspan="2"><?php echo $total['text']; ?></td>
<?php } ?>
</tr>
<?php } ?>

Alignment Error - HTML Tables

So I have this
<?php
$username = $_SESSION['username'];
$sql = mysql_query("SELECT * FROM `users` WHERE `username`='$username'");
while($row = mysql_fetch_array($sql))
{
$cash = $row['cash'];
$exp = $row['exp'];
$maxExp = $row['max_exp'];
$health = $row['health'];
$energy = $row['energy'];
$stanima = $row['stanima'];
$maxStanima = $row['max_stanima'];
$maxEnergy = $row['max_energy'];
?>
<div id="statsBox">
<table width="100%">
<tr>
<td width="2490px" height="20px">
<?php
echo '<b><font color="#00FF00" face="verdana">$'.$row['cash'].'</font></b>';
?>
</td>
<td width="5000px" height="20px">
<center>
<?php
echo '<b><font color="white" face="verdana">'.$energy.'/'.$maxEnergy.'</font></b>';
?>
</center></td>
<td width="2510px" height="20px">
<div class="right">
<?php
echo '<b><p class="White">'.$stanima.'/'.$maxStanima.'</p></b> ';
}
}
?>
</div>
</td>
</tr>
<div id="statsBox">
<table>
<tr>
<td width="2490px" height="20px">
<?php
echo '<b><font color="#00FF00" face="verdana">'.$health.'/100</font></b>';
?>
</td>
<td width="5000px" height="20px">
<center>
<?php
echo '<b><font color="white" face="verdana">'.$energy.'/'.$maxEnergy.'</font></b>';
?>
</center></td>
<td width="2510px" height="20px">
<div class="right">
<?php
echo '<b><p class="White">'.$stanima.'/'.$maxStanima.'</p></b> ';
?>
</td></tr>
</table>
</div>
</div>
</div>
I want the bottom 3 items to be moved up. Everything's inside 2 different tables. I've tried combining the tables but it messes up the alignment of the bottom middle item.
It's perfect how it is now, but I was wondering how I would decrease the table height somehow to make the bottom 3 items closer to the top?
in the second table, you can add class and specify its height in the css or simply add inline css in the second table
<table style="height:25px;">
Your need two Changes in your table
1. write a inline css in your table
<table width="100%" style="border-collapse: collapse;">
You need a inline css in your p tag in your td on both locations
<p class="White" style="margin:0px;"> </p>

Table row beside each other

I tried to allow the last td in this code to be beside the previous td, but I can't and the td is printed in a new line. How to allow them to be beside each other,the problem is that the 1st 5 td are in a foreach loop and the last td is not follow this foreach as it's value is a function and not a key or a value in the foreach.
<?php foreach($downloads as $dl) { ?>
<tr id="this">
<td ><img src="images/<?=$dl['type']?>.png"/></td>
<td id="no3"><?=$dl['type']?></td>
<td>
<a target="_blank" style="margin-right:3px" href="download.php?id=<?=$dl['id']?>">
<?=$dl['title']?>
</a>
</td>
<td>
<center>
<?=$dl['sname']?>
</center>
</td>
<td align="center"><?=$dl['views']?></td>
</tr>
<?php } ?>
<td align="center"><?=$core->use_love(); ?></td>
The function of the last td
public function use_love(){
$sql=mysql_query("select * from wcddl_downloads ORDER BY id DESC LIMIT ".$this->pg.",".$this->limit."");
while($row=mysql_fetch_array($sql))
{
$down_id=$row['id'];
$love=$row['love'];
?>
<div class="box" align="center">
<a href="#" class="love" id="<?php echo $down_id; ?>">
<span class="on_img" align="left"> <?php echo $love; ?> </span>
</a>
</div>
<?
}
}
The last <td> (the one outside the foreach loop) is on a new line because it's outside the last <tr> tag. One way to solve this is to always close the </tr> tag after the last <td>, like this:
<?php
$first_time = True;
foreach($downloads as $dl) {
// If this is the first time through the loop, don't echo a </tr> tag:
if ($first_time) {
$first_time = False;
} else {
echo "</tr>";
}
// Now print the new row, but don't close it yet:
?>
<tr id="this">
<td><img src="images/<?=$dl['type']?>.png"/></td>
<td id="no3"><?=$dl['type']?></td>
<td><a target="_blank" style="margin-right:3px" href="download.php?id=<?=$dl['id']?>"><?=$dl['title']?></a></td>
<td><center><?=$dl['sname']?></center></td>
<td align="center"><?=$dl['views']?></td>
<?php
}
?>
<td align="center"><?=$core->use_love(); ?></td>
</tr>
This will always put the last <td> in the final row.
UPDATE: I just saw you added a diagram. This answer now makes no sense as the text description given earlier has nothing to do with what you want to achieve in the diagram.
I submit the modification to Steve Nay's answer as you need the same number of TD in all your TR. When you don't have the same count, you need to use colspan to achieve it. I've added a counter to check if it's the last time you loop. Here it goes:
<?php
$downloads_count = count($downloads);
$counter = 0;
foreach($downloads as $dl) :
$counter++;
// If this is the first time through the loop, don't echo a </tr> tag:
if ($counter > 1) {
echo "</tr>";
}
// Now print the new row, but don't close it yet:
?>
<tr id="this">
<td><img src="images/<?=$dl['type']?>.png"/></td>
<td id="no3"><?=$dl['type']?></td>
<td><a target="_blank" style="margin-right:3px" href="download.php?id=<?=$dl['id']?>"><?=$dl['title']?></a></td>
<td><center><?=$dl['sname']?></center></td>
<td align="center"<?php if ($downloads_count != $counter) echo ' colspan="2"'; ?>><?=$dl['views']?></td>
<?php endforeach; ?>
<td align="center"><?=$core->use_love(); ?></td>
</tr>

Printing website correctly

I am trying to make a website that reads from a csv file and render the data on the screen in a printable format (it is for printing tickets). The page creates 2 tickets per row and loops threw until it runs out of data. It all works perfectly and looks just the way i want it but, when i print it the 3rd row down has one of the rows of text move up onto the line above it. My question is how can i make it print the way it is seen on the screen and why would it screw up only the 3rd row when all rows are made with the same code.
Thanks
EDIT:
while (!feof($file_handle)){`
$csvText = fgetcsv($file_handle, 1024);
$username = $csvText[1];
$password = $csvText[2];
$profile = $csvText[3];
$daysValid = $csvText[4];
$expiry = $csvText[5];
if($pos == 0)
{
if($count == 5){
echo "<p><br /></p>";
$count = 0;
}else{
$count++;
}
echo "<div class='itemRow'>";
echo "<div class='left'>";
$pos = 1;
?>
<h4 class="centre">Internet Access Voucher</h4>
<img class="image" src="./icon.jpg" />
<div class="info">
<table>
<tr>
<td>
Username
</td>
</tr>
<tr>
<td>
Password
</td>
</tr>
<tr>
<td>
Profile
</td>
</tr>
<tr>
<td>
Valid for
</td>
</tr>
<tr>
<td>
Expiry date
</td>
</tr>
</table>
</div>
<div class="uniqueInfo">
<table>
<tr>
<td>
<?php echo $username;?>
</td>
</tr>
<tr>
<td>
<?php echo $password;?>
</td>
</tr>
<tr>
<td>
<?php echo $profile;?>
</td>
</tr>
<tr>
<td>
<?php echo $daysValid;?>
</td>
</tr>
<tr>
<td>
<?php echo $expiry;?>
</td>
</tr>
</table>
</div>
<p class="centre"><br />Please remember to disconnect to stop each session.</p>
</div>
<br />
<?php
} else {
?>
<div class="right">
<h4 class="centre">Internet Access Voucher</h4>
<img class="imageRight" src="./icon.jpg" />
<div class="infoRight">
<table>
<tr>
<td>
Username
</td>
</tr>
<tr>
<td>
Password
</td>
</tr>
<tr>
<td>
Profile
</td>
</tr>
<tr>
<td>
Valid for
</td>
</tr>
<tr>
<td>
Expiry date
</td>
</tr>
</table>
</div>
<div class="uniqueInfoRight">
<table>
<tr>
<td>
<?php echo $username;?>
</td>
</tr>
<tr>
<td>
<?php echo $password;?>
</td>
</tr>
<tr>
<td>
<?php echo $profile;?>
</td>
</tr>
<tr>
<td>
<?php echo $daysValid;?>
</td>
</tr>
<tr>
<td>
<?php echo $expiry;?>
</td>
</tr>
</table>
</div>
<p class="centre"><br />Please remember to disconnect to stop each session.</p>
</div>
</div>
<?php
$pos = 0;
}
}
?>
CSS
.centre
{
text-align:center;
}
.itemRow
{
position:relative;
top:0px;
}
.left
{
width:500px;
position:relative;
font-family:Comic Sans, Comic sans MS, cursive;
/*border-style:solid;
border-width:1px;*/
}
.right
{
width:500px;
position:absolute;
left:600px;
top:-20px;
font-family:Comic Sans, Comic sans MS, cursive;
/*(border-style:solid;
border-width:1px;*/
}
.image
{
position:absolute;
top:70px;
}
.info
{
position:relative;
left:63px;
}
.uniqueInfo
{
position:absolute;
left:250px;
top:42px;
}
.infoRight
{
position:relative;
left:63px;
top:0px;
}
.uniqueInfoRight
{
position:absolute;
left:250px;
top:65px;
}
.imageRight
{
position:absolute;
top:90px;
}
I suspect this might be the problem:
if($count == 5){
echo "<p><br /></p>";
You have 2 per row, and increment $count after every ticket. So, $count = 5 would be after the fourth ticket, or when the third row starts. A sample HTML page would give me a better idea of what's going on exactly, but I'd suggest doing something like
<br style="clear: both;" />
between the rows to split them cleanly. So before ticket 3 and 5 ($count = 3 and $count = 5).

how to display data in two column with php

How can I display data in two columns?
<?php
$query = "SELECT * FROM `release` WHERE artist_id = '$rcode' AND label_id = '$id'";
$result = mysql_query($query);
$tr_no = mysql_num_rows($result);
while ($info = mysql_fetch_array($result)) {
?>
<div>
<table style="width: 100%">
<tr>
<td ><img src="../artwork/<?php echo $info['label_id']; ?>/<?php echo $info['ID']; ?>.jpg" width="100" height="100" /></td>
<td valign="top">
<table style="width: 100%">
<tr>
<td style="width: 45px; height: 20px;" class="style5">
</td>
<td style="width: 180px"><?php echo $info['code']; ?></td>
</tr>
<tr>
<td style="width: 45px; height: 20px;" class="style5">
</td>
<td style="width: 180px"><?php echo $info['name']; ?></td>
</tr>
<tr>
<td style="width: 45px; height: 20px;" class="style5">
</td>
<td style="width: 180px"><?php echo trh($info['date']); ?></td>
</tr>
<tr>
<td style="width: 45px; height: 20px;" class="style5">
</td>
<td style="width: 180px">
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<?php
}
?>
Normally I am using this for just one column.
What is the easiest way of displaying it in two columns with the same fields I have in this code?
The answer also depends on the way you'd like to show the info.
If we assume you have the following six artist_id's in your DB
1,2,3,4,5,6
in which way would you like to show them? This way
1 2
3 4
5 6
or this way?
1 4
2 5
3 6
Update: as you say you'd like to show them in the first way, the solution is pretty simple. Every pair iteration (0, 2, 4...) you should open the row and every odd iteration (1, 3, 5...) you should close it , so you'd have
<tr><td>0</td><td>1</td></tr><tr><td>2</td><td>3</td></tr>...
The code would be
<?php
$query = "SELECT * FROM `release` WHERE artist_id = '$rcode' AND label_id = '$id'";
$result = mysql_query($query);
$tr_no = mysql_num_rows($result);
$ii = 0; // Iterator
while ($info = mysql_fetch_array($result)) {
?>
<div>
<table style="width: 100%">
<?php if ($ii%2 == 0) { // If pair, we open tr?>
<tr>
<?php } ?>
<td ><img src="../artwork/<?php echo $info['label_id']; ?>/<?php echo $info['ID']; ?>.jpg" width="100" height="100" /></td>
<td valign="top">
<table style="width: 100%">
<tr>
<td style="width: 45px; height: 20px;" class="style5">
</td>
<td style="width: 180px"><?php echo $info['code']; ?></td>
</tr>
<tr>
<td style="width: 45px; height: 20px;" class="style5">
</td>
<td style="width: 180px"><?php echo $info['name']; ?></td>
</tr>
<tr>
<td style="width: 45px; height: 20px;" class="style5">
</td>
<td style="width: 180px"><?php echo trh($info['date']); ?></td>
</tr>
<tr>
<td style="width: 45px; height: 20px;" class="style5">
</td>
<td style="width: 180px">
</td>
</tr>
</table>
</td>
<?php if ($ii%2 == 1) { // If odd, we close tr?>
</tr>
<?php } ?>
</table>
</div>
<?php $ii++; // We increment the iterator }
?>
You have several options depending on how fancy you want to get with your HTML/CSS. You can try to keep each to 50% width and float them left and the elements should automatically arrange themselves in two columns.
You can also be more explicit using a table-based layout. In this case, start with a and tag, then add elements inside your loop. After every two elements ( $index % 2 == 0), write a to start a new row.. then, after your loop is finished, close your . If you go this route, you'll want to make sure to add an extra if you've got an odd number of results from your query.
There may be more sophisticated ways to do this, but this is simple and straightforward enough to get the job done.
Unless you have a "LARGE" data set,
1) bring all the rows out into a numerically indexed array
2) divide the number of rows by two: x1 = 0; x2 = (int) count/2;
3) loop from 0 to count/2, creating a table with two columns,
3a) those indexed by x1++ in the first column
Get the total number of pictures, you can do that dynamically, and then put everything in a for loop as follows:
Let's say you want 9 pictures on three columns:
for ($i = 0; $i<=6; $i=($i + 3))
{
$result = mysql_query("select * from users order by id desc limit $i,3 ");
while(mysql_fetch_array($result))
{
//bla bla bla html code
}
}
Good luck.
<table border='1'><tr><?phpfor ($i = 0; $i<=17; $i=($i + 3)){echo "<td>$i</td>";}?></tr><tr><?phpfor ($n = 1; $n<=17; $n=($n + 3)){ echo "<td>$n</td>";}?></tr><tr><?phpfor ($m = 2; $m<=17; $m=($m + 3)){echo "<td>$m</td>";}?></tr></table>
|0|3|6|9|12|15|
|1|4|7|10|13|16|
|2|5|8|11|14|17|
Thank you :)
<table border='1'><?phpfor ($n = 0; $n<=2; $n++) {echo "<tr>";for ($i = $n; $i<=17; $i=($i + 3)){ echo "<td>$i</td>";}echo "</tr>";}?></table>
just use two loop like this
result
0 3 6 9 12 15
1 4 7 10 13 16
2 5 8 11 14 17

Categories