How to add contents in new page using TCPDF? - php

I am using TCPDF stuff, I have created a PDF page with some Information. But i need to show some data to next page deliberately.
pdf -> AddPage();
above code is used to create a new page which i know. But i wanna add specific data to this particular page would be the problem.
Help me to come out on this issue.
I have written my code like this
while($row = mysql_fetch_array($query)){
$inv = $row["INVNUM"];
$weight = $row["WEIGHT"];
if($i<4){
if($row["SIZECODE"] == "02"){
$temp .= '<tr nobr="true">
<td class="size1" style="border:1px solid #000">'.$json_a[$i]["S"].'</td>
<td class="size2" style="border:1px solid #000">'.$json_a[$i]["M"].'</td>
<td class="size3" style="border:1px solid #000">'.$json_a[$i]["L"].'</td>
<td class="size4" style="border:1px solid #000">'.$json_a[$i]["XL"].'</td>
<td class="size5" style="border:1px solid #000">'.$json_a[$i]["2X"].'</td>
<td class="size6" style="border:1px solid #000">'.$json_a[$i]["3X"].'</td>
</tr>';
}
else if($row["SIZECODE"] == "03"){
$temp .= '<tr>
<td style="border:1px solid #000">'.$json_a[$i]["32"].'</td>
<td style="border:1px solid #000">'.$json_a[$i]["34"].'</td>
<td style="border:1px solid #000">'.$json_a[$i]["36"].'</td>
<td style="border:1px solid #000">'.$json_a[$i]["38"].'</td>
<td style="border:1px solid #000">'.$json_a[$i]["40"].'</td>
<td style="border:1px solid #000">'.$json_a[$i]["42"].'</td>
</tr>';
}
$i = $i+1;
}
else{
$pdf ->AddPage();
$i = 0;
$temp.='<tr nobr="true">
<td colspan="18" style="border:1px solid #000">All sales are Final.</td>
<td colspan="2" style="border:1px solid #000">SUB TOTAL:</td>
<td style="border:1px solid #000"></td>
<td style="border:1px solid #000"></td>
</tr>
<tr>
<td colspan="18" rowspan="2" style="border:1px solid #000">Number # : '.$rowFix["Num"].' </td>
</tr>
<tr>
<td colspan="2">TOTAL DUE: $</td>
<td style="border:1px solid #000"></td>
<td style="border:1px solid #000"></td>
</tr>';
}
}
I have to bring the table rows to the next page when the $i value greater than 4.

$pdf->AddPage('P', 'A4');
$pdf->Cell(0, 0, 'A4 PORTRAIT', 1, 1, 'C');

First, output the content for the first page. Then:
pdf -> AddPage();
Then, output for the second page. Anything sent after this command will be outputted onto the second page.

Related

foreach cicle with math of previous row table

Hello i need some help with this problem.
I'm printing a table with database values, but in one row field it will be math...
So like this example table.
<table style="border:1px solid black;">
<thead style="background:black;color:white;">
<th style="border:1px solid black;">date</th>
<th style="border:1px solid black;">debt</th>
<th style="border:1px solid black;">cred</th>
<th style="border:1px solid black;">result</th>
</thead>
<tbody>
<!-- foreach -->
<tr>
<td style="border:1px solid black;">01-10-2020</td>
<td style="border:1px solid black;">1000</td>
<td style="border:1px solid black;">100</td>
<!-- the follwing result is 1000-100 -->
<td style="border:1px solid black;">900</td>
</tr>
<tr>
<td style="border:1px solid black;">02-10-2020</td>
<td style="border:1px solid black;">0</td>
<td style="border:1px solid black;">200</td>
<!-- the follwing result is (0-200)+900 -->
<td style="border:1px solid black;">700</td>
</tr>
<tr>
<td style="border:1px solid black;">03-10-2020</td>
<td style="border:1px solid black;">150</td>
<td style="border:1px solid black;">0</td>
<!-- the follwing result is (150-0)+700 -->
<td style="border:1px solid black;">850</td>
</tr>
<!-- end foreach -->
</tbody>
</table>
So i expect the result field with this formula (debt - cred)+previous result of the row before, the first row the is (debt-cred)+0...and the maths star after the first row.
This might help you along, slightly back to front of what you have:
<?php
$data =
[
[100, 20],
[20, 0],
[0, 50]
];
$balance = 0;
foreach($data as $row) {
$balance += $row[0] - $row[1];
printf("Cred: %d, Debt: %d, Balance: %d.\n", $row[0], $row[1], $balance);
}
Output:
Cred: 100, Debt: 20, Balance: 80.
Cred: 20, Debt: 0, Balance: 100.
Cred: 0, Debt: 50, Balance: 50.

TCPDF table header automatically move to the right

I have created a table with TCPDF. The header, which has a black background, has been positioned slightly to the right as though there is some padding on the left hand side. I cannot get it to line up correctly.
The code below is the HTML I have written to form the table.
$tbl ='<style>
th {background-color: black;color: white;float:left;}
.tal {text-align: left;float:left;}
</style>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="60px" style="border-right: 1px solid white;"><strong>Qty</strong></th>
<th width="1px"></th>
<th class="tal" width="388px" style="padding:10px 0; border-right: 1px solid white;"> <strong>Product or Service</strong></th>
<th width="1px"></th>
<th width="84px" style="border-right: 1px solid white;"><strong>Price Each</strong></th>
<th width="1px"></th>
<th width="84px"><strong>Total</strong></th>
</tr>
<tr>
<td height="267px">';
while($i <= $a) {
$tbl .= '<table height="267px" width="60px"><tr><td>' . $productsArray['product_quantity'][$i] . '</td></tr></table>';
$i++;
}
$tbl .= '</td><td border="1" width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td><td height="267px">';
while($j <= $a) {
$tbl .= '<table height="267px" width="388px"><tr><td class="tal"> ' . $productsArray['product_name'][$j] . '</td></tr></table>';
$j++;
}
$tbl .= '</td><td width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td><td height="267px">';
while($k <= $a) {
$tbl .= '<table height="267px" width="84px"><tr><td>' . $productsArray['product_price'][$k] . '</td></tr></table>';
$k++;
}
$tbl .= '</td><td border="1" width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td><td height="267px">';
while($l <= $a) {
$tbl .= '<table height="267px" width="84px"><tr><td>' . $productsArray['product_sub'][$l] . '</td></tr></table>';
$l++;
}
$tbl .= '</td>
</tr>
</table>';
}
The below code is the PHP I have used to show the table on the page.
$pdf->writeHTMLCell(175, 80, 20, 100, $tbl, 1, 1, 0, true, 'C', true);
Using tables within cells of another table is generally a really bad idea and is likely contributing to the problem you are having. Since it looks like your productsArray already has all of the data you need I would simply loop through it outputting each row as you go.
It's also worth pointing out that the empty header rows that are defined with a width of 1px conflict with your actual data rows which are defined with a width of 0.5px.
<style>
th {background-color: black;color: white;float:left;}
.tal {text-align: left;float:left;}
</style>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="60px" style="border-right: 1px solid white;"><strong>Qty</strong></th>
<th width="1px"></th>
<th class="tal" width="388px" style="padding:10px 0; border-right: 1px solid white;"> <strong>Product or Service</strong></th>
<th width="1px"></th>
<th width="84px" style="border-right: 1px solid white;"><strong>Price Each</strong></th>
<th width="1px"></th>
<th width="84px"><strong>Total</strong></th>
</tr>
<?php
while($i <= $a) {
?>
<tr>
<td height="267px"><?php echo $productsArray['product_quantity'][$i]; ?></td>
<td border="1" width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td>
<td height="267px"><?php echo $productsArray['product_name'][$i]; ?></td>
<td width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td>
<td height="267px"><?php echo $productsArray['product_price'][$i]; ?></td>
<td border="1" width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td>
<td height="267px"><?php echo $productsArray['product_sub'][$l]; ?></td>
</tr>
<?php
$i++;
}
?>
</table>

PHP & Virtuemart: change color of a number if this number is bigger than 1

The code at the virtumart is:
<th align="center" bgcolor="#EEEEEE" style="border: 1px solid #CCCCCC;"><?php echo JText::_('COM_VIRTUEMART_ORDER_PRINT_QTY') ?></th>
What I need is the following:
When the COM_VIRTUEMART_ORDER_PRINT_QTY is bigger than 1, the font color to be somehtinge else, for example red (the format I will do it later, now I just want the "if" code).
Thanks
Please try
<?php
$quantity = JText::_('COM_VIRTUEMART_ORDER_PRINT_QTY');
if($quantity > 1){
echo '<th align="center" bgcolor="#EEEEEE" style="border: 1px solid #CCCCC; color:#FF0000">'.$quantity.'</th>';
}else{
echo '<th align="center" bgcolor="#EEEEEE" style="border: 1px solid #CCCCCC;">'.$quantity.'</th>';
}
?>

HTML Email not sending properly When using CRON

Hi I am using codeigniter framework and CentOS. I am using a cron to send an html email , it calls to a php file from the cron , from the file i use ths command to call to a codegniter function
system("elinks -dump http://localhost/mailsender/index.php/mail/send/$email_job_id/");
from that i generate an html email .but the email html is not sending properly .
when i view the source of emil in my outlook , i can see ( this only a part of table )
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">Please check the Type Extension list.<br><br><table cellpadding="3D3D3D3D3=" D3="3D" D?="3D3D" 10="3D3D3D" ?="3D3D3D3D" st="3D3D3D3D3D" yle="3D3D3D3D3D3D"border:1px" solidblack;border-collapse:collapse;?="">
<tr>
<td style="3D3D3D3D3D3D"border:1px" solidblack;?="">Model</td>
<td style="3D3D3D3D3D3D"border:1px" solidblack;?="">Description</td>
<td style="3D3D3D3D3D3D"border:1px" solidblack;?="">Et</td>
<td style="3D3D3D3D3D3D"border:1px" solidblack;?="">Option Codes</td>
<td style="3D3D3D3D3D3D"border:1px" solidblack;?="">Order numbers</td>
</tr>
<tbody>
<tr><td style="3D3D3D3D3D3D"border:1px" solidblack;?="">2E32</td><td style="3D3D=" 3D3D="3D" 3D3D="3D3D" ?bor="3D3D3D" der:="3D3D3D3D" 1px="3D3D3D3D3D" solidblack;?="">216D GRAN TOURER RHD</td><td style="3D3D3D3D3D3D"border:1px" so="li=3D" d="3D3D" bl="3D3D3D" ac="3D3D3D3D" k;="3D3D3D3D3D" ?="">205,402,4UB,7LG</td><td style="3D3D3D3D3D3D"border:1px" solidblack;?="">2=
20=3D
97=3D3D
23=3D3D3D
76=3D3D3D3D
</=3D3D3D3D3D></tr>
My Mail sending function
function send($id) {
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['useragent'] = 'GSPL';
$config['smtp_host'] = 'smtp.***';
$config['smtp_user'] = '';
$config['smtp_pass'] = '';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->from("***");
$this->email->reply_to("***");
$this->email->subject("***");
$this->email->set_mailtype("html");
$new_email_body = $this->create_email_body();
$data->body = $new_email_body;
$this->email->message($data->body);
$this->email->to("*****");
$this->email->send();
}
create_email_body function will call to a view with the data
<table cellpadding="10" style="border:1px solid black;border-collapse: collapse;">
<tr>
<td style="border:1px solid black;">Model</td>
<td style="border:1px solid black;">Description</td>
<td style="border:1px solid black;">Et</td>
<td style="border:1px solid black;">Option Codes</td>
<td style="border:1px solid black;">Order numbers</td>
</tr>
<tbody>
<?php
foreach($result as $row)
{
echo '<tr><td style="border:1px solid black;">'.$row["model"].'</td><td style="border:1px solid black;">'.$row["description"].'</td><td style="border:1px solid black;">'.$row["et"].'</td><td style="border:1px solid black;">'.$row["option_codes"].'</td><td style="border:1px solid black;">'.$row["order_numbers"].'</td></tr>';
}
?>
</tbody>
<table>
Is there any way to send the correctly formatted HTML . Thank you in advance .
NOTE
The email is sending correctly formatted when i run the below directly in the browser .
http://localhost/mailsender/index.php/mail/send/***/
Table source i can see in outlook
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">Please check the Type Extension list.<br><br><table cellpadding="10" style="border:1px solid black;border-collapse: collapse;">
<tr>
<td style="border:1px solid black;">Model</td>
<td style="border:1px solid black;">Description</td>
<td style="border:1px solid black;">Et</td>
<td style="border:1px solid black;">Option codes</td>
<td style="border:1px solid black;">Order numbers</td>
</tr>
<tbody>
<tr><td style="border:1px solid black;">ABCD</td><td style="border:1px solid black;">test</td><td style="border:1px solid black;">ABC</td><td style="border:1px solid black;">222,222,22</td><td style="border:1px solid black;">22222,22222,2222</td></tr> </tbody>
<table>
Is there a reason why you use system and elinks?
You could running the cronjob via the CLI:
php path/to/index.php mail send "some_id"
Did you also tried it with wget or curl?

PHP Table Hyperlink

I have a table that returns information from mysql. However, I want to hyperlink each postcode so that when the user clicks on one it will redirect them to an appropriate page. Here is the code that is in the table:
<table style="border:2px solid black; border-collapse:collapse;" cellspacing="2" cellpadding="2" align="center">
<tr align="center" width="auto">
<td bgcolor="#66CCFF" style="border:2px solid black;"><b> Consultation Date </b></td>
<td bgcolor="#66CCFF" style="border:2px solid black;"><b> Patient Health Care Number </b></td>
<td bgcolor="#66CCFF" style="border:2px solid black;"><b> Location </b></td>
<td bgcolor="#66CCFF" style="border:2px solid black;"><b> Post Code </b></td>
<td bgcolor="#66CCFF" style="border:2px solid black;"><b> Update Record </b></td>
</tr>
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"Consultation Date");
$f2=mysql_result($result,$i,"Patient HCN");
$f3=mysql_result($result,$i,"Location");
$f4=mysql_result($result,$i,"Post Code");
?>
<tr>
<td align="center" bgcolor="#FFFFFF" style="border:2px solid black;"><?php echo $f1; ?></td>
<td align="center" bgcolor="#FFFFFF" style="border:2px solid black;"><b><?php echo $f2; ?></b></td>
<td align="center" bgcolor="#FFFFFF" style="border:2px solid black;"><?php echo $f3; ?></td>
<td align="center" bgcolor="#FFFFFF" style="border:2px solid black;"><?php echo "<a href=\"coveragehcp.php?patient= ". $f2 ."\">"?><b><?php echo $f4; ?></b></td>
<td align="center" bgcolor="#FFFFFF" style="border:2px solid black;"><?php echo "<button onclick=\"window.location.href='hcp_form_update.php?patient=$f2'\">"?>Update Record</button></td> <!-- This button redirects the user to the auto-populated form that holds the patients information which allows the user to update it -->
</tr>
<?php
$i++;
}
?>
However when the user click on the link below I want it to redirect them to another page according to the post code clicked.
<td align="center" bgcolor="#FFFFFF" style="border:2px solid black;"><?php echo "<a href=\"coveragehcp.php?patient= ". $f2 ."\">"?><b><?php echo $f4; ?></b></td>
What I would do is to use the post code as a parameter in the GET, and then use the $_GET['postcode'] to achieve which page should be presented for the user.
so your PHP code for the link would look something like:
<a href=\"coveragehcp.php?patient= ".$f2."&postcode=".$f4."\">"?><b><?php echo $f4; ?></b></td>
and on the coveragehcp.php page use this
$postcode = $_GET['postcode'];
if(!empty($postcode))
{
if($postcode == 90210) {
//Echo beverly hills page
}
else {
//Echo default page
}
}

Categories