I have a file that converts my MySQL data to PDF using dompdf it works fine but sometimes it just throws 500 error and nothing shows up and after a few moments works and sometimes I am supposed to put a clean back up for it to work. All the is collected successfully with mysql and php but at last some errors in converting the PDF dont know is it dompdf bug or problem with my code. Please check the code below and help me make a better world... I greatly appreciate your help :)
<?php
$idswitch = $_GET['id']; // id for viewing
// Below is optional, remove if you have already connected to your database.
$mysqli = mysqli_connect('...', '..', '..', '...');
$sql=mysqli_query($mysqli,"SELECT * FROM si_invoices WHERE id='$idswitch'")or die(mysql_error());
$row=mysqli_fetch_assoc($sql);
$sample .= "<div style='font-family: Arial, Helvetica, sans-serif; background:#000000; width: 100%; color: #ffffff; padding: 4px; text-align: center; font-size: 120%;' >PROFOMA INVOICE: ID:100".$row['id']."</div>";
$sample .= "<div style='width:100%; height: 120px; background: #ffffff;'>";
$sample .= "<img src='logo-si.png' style='width: 250px; padding: 15px'>";
$sample .= "<div style='font-family: Arial, Helvetica, sans-serif; background:#000000; width: 100%; color: #ffffff; padding: 4px; text-align: center; font-size: 75%' >Interior Exterior General Signs LED Architectural & Modular Sign Systems Traffic & Safety Signs MV No. Plates</div><br>";
$sample .= "<div style='font-family: Arial, Helvetica, sans-serif; position:absolute; top: 35px; left: 300px; width: 400px; border-left: 2px solid #000000; padding-left: 10px; background: #ffffff; font-size: 85%'>
UBUNGO BUSINESS PARK-P.O.BOX 1965 - <br>DAR ES SALAAM-TANZANIA- +255 22 2866500 / 2860440 -<br>068444 422
E-MAIL: headsales#signindustries.co.tz - info#signindustries.co.tz - www.signindustries.co.tz
</div>";
$sample .= "</div>";
$sample .= "<div style='width:100%; margin-top: 15px;'>
<div style='float:left; width: 400px; height:margin-right: 10px;'>
<table style='width: 100%; height: 175px; border: 1px solid #000000; padding: 3px; font-size: 90%; font-family: Arial, Helvetica, sans-serif;'>
<tr>
<th align='left'></th>
<th align='left'></th>
</tr>
<tr>
<td width='30%'>Main Client:</td>
<td width='65%' align='left' style='border: 1px solid #000000;'>".$row['main_client']."</td>
</tr>
<tr>
<td width='30%'>Postal Address:</td>
<td width='65%' align='left' style='border: 1px solid #000000;'>".$row['postal_address']."</td>
</tr>
<tr>
<td width='30%'>Contact Person:</td>
<td width='65%' align='left' style='border: 1px solid #000000;'>".$row['contact_person']."</td>
</tr>
<tr>
<td width='30%'>Telephone / Cell:</td>
<td width='65%' align='left' style='border: 1px solid #000000;' >".$row['cell_offc']."</td>
</tr>
<tr>
<td width='30%'>Office Location:</td>
<td width='65%' align='left' style='border: 1px solid #000000;' >".$row['office_loc']."</td>
</tr>
<tr>
<td width='30%'>Email Address:</td>
<td width='65%' align='left' style='border: 1px solid #000000;' >".$row['email_addr']."</td>
</tr>
<tr>
<td width='30%'>Job Title:</td>
<td width='65%' align='left' style='border: 1px solid #000000;' >".$row['job_title']."</td>
</tr>
</table>
</div>
<div style='float:right; width: 40%; border: '>
<table style='width: 100%; height: 175px; border: 1px solid #000000; padding: 3px; font-size: 90%; font-family: Arial, Helvetica, sans-serif;'>
<tr>
<th align='left'></th>
<th align='left'></th>
</tr>
<tr>
<td colspan='2' align='center' style='background: #000000; color: #ffffff;'>Customer Tax Information:</td>
</tr>
<tr>
<td>TIN#:</td>
<td align='left' style='border: 1px solid #000000;' >".$row['clnt_tin']."</td>
</tr>
<tr>
<td>VRN#</td>
<td align='left' style='border: 1px solid #000000;' >".$row['clnt_vrn']."</td>
</tr>
<tr>
<td>VAT Exempted:</td>
<td align='left' style='border: 1px solid #000000;'>".$row['vat_expt']."</td>
</tr>
<tr>
<td>Exemption Cert</td>
<td align='left' style='border: 1px solid #000000;' >".$row['expt_cert']."</td>
</tr>
<tr>
<td colspan='2' align='center' style='background: #000000; color: #ffffff;'>Our Tax Information:</td>
</tr>
<tr>
<td>TIN#:</td>
<td align='left' style='border: 1px solid #000000;'>".$row['our_tin']."</td>
</tr>
<tr>
<td>VRN#:</td>
<td align='left' style='border: 1px solid #000000;' >".$row['our_vrn']."</td>
</tr>
</table>
</div>
<div style='clear:both;'>
</div>
<div>
</div>
</div>";
$sample .= "<table style='width: 100%; font-family: Arial, Helvetica, sans-serif; ' >
<tr>
<th align='center' style='border: 1px solid #000000;' >Requested Date:</th>
<th align='center' style='border: 1px solid #000000;'>Requested By:</th>
<th align='center' style='border: 1px solid #000000;'>Sales Person:</th>
</tr >
<tr>
<td align='center' style='border: 1px solid #000000;'>".$row['date_created']."</td>
<td align='center' style='border: 1px solid #000000;'>".$row['prepared_by']."</td>
<td align='center' style='border: 1px solid #000000;'>".$row['sales_person']."</td>
</tr>
</table>";
$idfk = $row['inv_code']; // id for viewing
$subtotl = $row['sub_totl']; // id for viewing
$vattotl = $row['vat_percent']; // id for viewing
$grandtotl = $row['grand_total']; // id for viewing
$dis_perc_sub = $row['dis_perc_sub']; // id for viewing
$lpouser = $row['lpo_user']; // id for viewing
$lpostatus = $row['lpo_status']; // id for viewing
$servername = "...";
$username = "...";
$password = "...";
$dbname = "....";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM itemsinv WHERE invidfk='$idfk' ORDER BY ln_no ASC";
$result = mysqli_query($conn, $sql);
$count = 0;
$sample .= "<table cellspacing='1' cellpadding='1' style='width:100%; border: 1px solid black; font-family: Arial, Helvetica, sans-serif; margin-top: 20px 0 0 0;
th, td { padding: 5px;}' >
<tr>
<th align='center' style='background: #000000; color: #ffffff; '>No</th>
<th align='center' style='background: #000000; color: #ffffff; '>Product Details</th>
<th align='center' style='background: #000000; color: #ffffff; '>Price</th>
<th align='center' style='background: #000000; color: #ffffff; '>Qty</th>
<th align='center' style='background: #000000; color: #ffffff; '>Total</th>
</tr>";
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$count++;
$sample .= "<tr>
<td style='border: 1px solid black;'>" .$count. "</td>
<td style='border: 1px solid black;'><b>" . $row['productname']. "</b><br>" . $row['particulars']. "</td>
<td style='border: 1px solid black;'>". $row['price']. "</td>
<td style='border: 1px solid black;'>". $row['qty']. "</td>
<td style='border: 1px solid black;'>". $row['item_total']. "</td>
</tr>";
}
} else {
echo "0 results";
}
$sample .= "<tr><td align='right' colspan='4'><b>Sub Total:</b></td><td align='left' style='border: 1px solid #000000;'>".$subtotl."</td></tr>";
$sample .= "<tr><td align='right' colspan='4'><b>VAT Total:</b></td><td align='left' style='border: 1px solid #000000;'>".$vattotl."</td></tr>";
$sample .= "<tr><td align='right' colspan='4'><b>Discount %:</b></td><td align='left' style='border: 1px solid #000000;'>".$dis_perc_sub."</td></tr>";
$sample .= "<tr ><td align='right' colspan='4'><b>Grand Total:</b></td><td align='left' style='border: 1px solid #000000;'>".$grandtotl."</td></tr>";
$sample .= "</table>";
$sample .= "<br><b style='font-family: Arial, Helvetica, sans-serif; font-size: 70%;'>Please read our terms and conditions by visiting our website. http://signindustries.co.tz</b>";
mysqli_close($conn);
// create pdf of invoice
$invoiceFileName = 'Invoice-'. $row["contact_name"]. '.pdf';
require_once 'dompdf/src/Autoloader.php';
Dompdf\Autoloader::register();
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->loadHtml(html_entity_decode($sample));
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream($invoiceFileName, array("Attachment" => false));
?>
Error log below
Stack trace:
#0 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4870): Imagick->writeimage('/tmp/cpdf_img_e...')
#1 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4984): Cpdf->addImagePngAlpha('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562, 6)
#2 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Adapter/CPDF.php(864): Cpdf->addPngFromFile('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562)
#3 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Renderer/Image.php(110): Dompdf\Adapter\CPDF->image('/home/crmsignin...', 45.265748031496, 68.848148031496, 187.5, 35.112359550562, 'normal')
#4 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Renderer.php(293): Dompdf\Renderer\Image->render(Object(Dompdf\FrameDecorator\I in /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php on line 4870
[06-Jul-2020 13:58:06 UTC] PHP Warning: Version warning: Imagick was compiled against Image Magick version 1650 but version 1654 is loaded. Imagick will run but may behave surprisingly in Unknown on line 0
[06-Jul-2020 13:58:06 UTC] PHP Fatal error: Uncaught ImagickException: WriteBlob Failed `/tmp/cpdf_img_QpfKj7.png' # error/png.c/MagickPNGErrorHandler/1755 in /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php:4870
Stack trace:
#0 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4870): Imagick->writeimage('/tmp/cpdf_img_Q...')
#1 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4984): Cpdf->addImagePngAlpha('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562, 6)
#2 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Adapter/CPDF.php(864): Cpdf->addPngFromFile('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562)
#3 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Renderer/Image.php(110): Dompdf\Adapter\CPDF->image('/home/crmsignin...', 45.265748031496, 68.848148031496, 187.5, 35.112359550562, 'normal')
#4 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Renderer.php(293): Dompdf\Renderer\Image->render(Object(Dompdf\FrameDecorator\I in /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php on line 4870
[06-Jul-2020 13:59:05 UTC] PHP Warning: Version warning: Imagick was compiled against Image Magick version 1650 but version 1654 is loaded. Imagick will run but may behave surprisingly in Unknown on line 0
[06-Jul-2020 13:59:05 UTC] PHP Fatal error: Uncaught ImagickException: WriteBlob Failed `/tmp/cpdf_img_0wDRir.png' # error/png.c/MagickPNGErrorHandler/1755 in /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php:4870
Stack trace:
#0 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4870): Imagick->writeimage('/tmp/cpdf_img_0...')
#1 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4984): Cpdf->addImagePngAlpha('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562, 6)
#2 /home/host/public_html/crm/admins/dompdf/src/Adapter/CPDF.php(864): Cpdf->addPngFromFile('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562)
#3 /home/host/public_html/crm/admins/dompdf/src/Renderer/Image.php(110): Dompdf\Adapter\CPDF->image('/home/crmsignin...', 45.265748031496, 68.848148031496, 187.5, 35.112359550562, 'normal')
#4 /home/host/public_html/crm/admins/dompdf/src/Renderer.php(293): Dompdf\Renderer\Image->render(Object(Dompdf\FrameDecorator\I in /home/host/public_html/crm/admins/dompdf/lib/Cpdf.php on line 4870
Related
I'm trying to create a PDF file via mPDF where the page continues. However, the second page write over the first
Code:
require_once ('../database/conection.php');
$db->query("SET NAMES 'utf8'");
$db->query("SET character_set_connection=utf8");
$db->query("SET character_set_client=utf8");
$db->query("SET character_set_results=utf8");
$sql = $db->query("SELECT * FROM movconsumo");
require_once __DIR__ . '/../vendor\autoload.php';
$mpdf = new \Mpdf\Mpdf();
$data = '';
while ($row = $sql->fetch(PDO::FETCH_ASSOC)) {
$data .= "<tr style='border: 1px solid black; border-collapse: collapse;'> <td style='border: 1px solid black; border-collapse: collapse;'>".$row['datamov']."</td>";
$data .= "<td style='border: 1px solid black; border-collapse: collapse;'>".$row['nomeitem']."</td>";
$data .= "<td style='border: 1px solid black; border-collapse: collapse;'><center>".$row['quantmov']."</center></td>";
$data .= "<td style='border: 1px solid black; border-collapse: collapse;'>".$row['destinomov']."</td>";
$data .= "<td style='border: 1px solid black; border-collapse: collapse;'>".$row['histmov'].'</td></tr>';
}
$mpdf->SetHTMLHeader('
<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 14pt; color: #000000; font-weight: bold; border-bottom:0.5mm solid #220044;">
<tr>
<td width="50%"><span style="font-weight: bold;">RELATÓRIO ITENS MOVIMENTADOS</span></td>
<td width="45%" style="text-align: right;"><span style="font-size: 9pt;">teste<br /></span></td>
<td width="5%" style="text-align: right;"><img src="../images/teste.png" width="100" height="105" /></td>
</tr>
</table><br><center>
<table style="border: 1px solid black; border-collapse: collapse; ">
<tr style="border: 1px solid black; border-collapse: collapse; ">
<th>DATA</th>
<th>NOME</th>
<th>QUANTIDADE</th>
<th>DESTINO</th>
<th>HISTÓRICO</th>
</tr>
'.$data."</table></center>");
//#--> page
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list
$mpdf->AddPage('L'); // Adds a new page in Landscape orientation L/P
//
$dia = date('d/m/y');
//#--> footer
$mpdf->SetHTMLFooter('
<table width="100%" style="vertical-align: bottom; font-family: serif; font-size: 8pt; color: #000000; font-weight: bold; font-style: italic;">
<tr>
<td width="33%"><span style="font-weight: bold; font-style: italic;">'.$dia.'</span></td>
<td width="33%" align="center" style="font-weight: bold; font-style: italic;">{PAGENO}/{nbpg}</td>
<td width="33%" style="text-align: right; ">Teste</td>
</tr>
</table>
');
$mpdf->Output();
I tried every way to keep the text going, however, it keeps writing on the first page.
I am using mpdf 8.1 with yii2 and PHP version is 7.4 for PDF report download. It's works fine in local environment. But the text keeps writing on the first page.
I am just making a railway reservation project to my college therefor I have to get passenger details and make a 2d array and send it to another page to show the summary but I just don't know how to do that.
my code is
<?php
include('connection.php');
session_start();
$train_number = $_GET['train_number'];
$train_name = $_GET['train_name'];
$coachid = $_GET['coachid'];
$date = $_SESSION['date'];
$day = $_SESSION['day'];
$coachtype = $_SESSION['coachtype'];
$useremail = $_SESSION['useremail'];
if($_SERVER['REQUEST_METHOD']='POST')
{
if(!empty($_POST['proceed']))
{
$i = 1;
while($i<7)
{
"What to write here";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Buy Tickets </title>
<link rel="stylesheet" href="css.css">
</head>
<body>
<div class="wrapper">
<div class="header">
<img src="banner.jpg" height="100%" width="100%"/>
</div>
<div class="navbar">
<ul>
<li>Dashboard </li>
<li>Buy Ticket </li>
<li>Cancel ticket</li>
<li>Edit Profile</li>
<li id="last">Logout</li>
</ul>
</div>
<div>
<?php
echo "<h4 align='center'><u>Booking for </u></h4>";
echo "<table align='center'>
<thead>
<tr style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Train Number </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Train name </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Date </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Coach type </th>
</tr>
</thead>";
echo "<tr>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>".$train_number."</td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>".$train_name."</td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>".$date."</td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>".$coachtype."</td>";
echo "</tr>";
echo "</table>";
echo "<h4 align='center'><u>Passenger details </u></h4>";
echo "<table align='center'>
<thead>
<tr style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> No </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Passenger Name </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Age </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Gender type </th>
</tr>
</thead>";
$iforlist = 1;
while($iforlist<7)
{
echo "<form method='post'>";
echo "<tr>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>".$iforlist."</td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'><input type='text' name='passenger_name.".$iforlist."' value='' placeholder='Enter name '></td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'><input type='number' name='passenger_age.".$iforlist."' value='' max='100' min='1' placeholder='Enter passenger age '></td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'><select name='passenger_gender.".$iforlist."'>
<option value='Male'>Male</option>
<option value='Female'>Female</option>
</select></td></td>";
echo "</tr>";
$iforlist++;
}
echo "</table>";
echo "<div align='center' style='margin-top:10px;'><input type='submit' align='center' name='proceed' value='Proceed' style='width:100px;height:40px;' placeholder='Enter name '></div>";
echo "</form>";
?>
</div>
</div>
</body>
</html>
So, tell me how can i make fetch data if only 2 or 3 field are filled and make a 2d array of it.
if you want any other information i'll give you..
Here is an example of how to use 2D Arrays in PHP
$cars = array
(
array("Volvo",22,18),
array("BMW",15,13),
array("Saab",5,2),
array("Land Rover",17,15)
);
Now to access the data, you must specify the row and column:
<?php
echo $cars[0][0].": In stock: ".$cars[0][1].", sold: ".$cars[0][2].".<br>";
echo $cars[1][0].": In stock: ".$cars[1][1].", sold: ".$cars[1][2].".<br>";
echo $cars[2][0].": In stock: ".$cars[2][1].", sold: ".$cars[2][2].".<br>";
echo $cars[3][0].": In stock: ".$cars[3][1].", sold: ".$cars[3][2].".<br>";
?>
In this case:
array("Volvo",22,18)
That is a single row (0) and it has three columns (Volvo at row=0 column=0, 22 at row=0 colum=1, etc)
I took the example from here: https://www.w3schools.com/php/php_arrays_multi.asp
Let me know if this helps.
Working on invoice module which has two different tables master_table and detail_table. Know i want to display master_table's data above the table then in the table structure showing data of detail_table for each three rows header.
My code looks this.
$n = 0;
$htmlpage = 1;
$query = $dbConnection->prepare("SELECT * FROM master WHERE (DocNo BETWEEN ? AND ?) ORDER BY DocNo ASC");
$query->execute(array($fdcu,$tdcu));
while($rows = $query->fetch())
{
$n++;
$noInvs = $rows['No_of_Inv'];
$dno = $rows['DocNo'];
$name = $rows['Customer_Name'];
Step-1: Now i'm pulling client data from another table
$qry = $dbConnection->prepare("SELECT * FROM client WHERE client_name=?");
$qry->execute(array($name));
$row = $qry->fetch();
$add = $row['address'];
$city = $row['city'];
$proj = $rows['Project'];
$projNo = $rows['Project_No'];
$sermnth = $rows['Service_Month'];
$grandtotal = $rows['Total_Amt'];
$rupee = number2word($grandtotal);
$index = 1;
$ratetot = 0;
$subtotal = 0;
$lastPage = ceil($noInvs/3);
$pageCount = 0;
Step-2: Now check the loop iteration
while($index <= $noInvs)
{
$cnt = 1;
$body = "<div class='main-container'><table width='100%' style='padding:0 0 0 0;' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td valign='top' align='center' style='border:1px solid #000;'>
<strong style='font-size:30px;'>Data</strong>
</td>
</tr>
<tr>
<td valign='top' align='left' style='padding: 0 0px 0 0px;border-left: solid 1px #000000;border-right: solid 1px #000000;border-bottom: solid 1px #000000;'>
<table width='100%' align='left' cellpadding='0' cellspacing='0'>
<tr>
<td valign='top' style='width:50%; padding:5px; font-size:13px; border-right: solid 1px #000000;text-align:left;'><strong>CUSTOMER:</strong> <br /><p style='font-size:12px;'>$name<br />$add, $city</p></td>
<td valign='top' style='width:50%; font-size:13px;'>
<table width='100%' cellpadding='0' cellspacing='0'>
<tbody>
<tr>
<td style='border-right: solid 1px #000000;padding:5px;width:40%;font-size:12px;'><br />Invoice No:<br />Invoice Date:</td>
<td align='left' style='padding:5px;font-size:12px;'><br />$ino<br />$invdate</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign='top' align='left' style='border-left: solid 1px #000000;border-right: solid 1px #000000;border-bottom: solid 1px #000000;'>
<table width=100% cellpadding='0' cellspacing='0' >
<tbody>
<tr style='border-right:solid 1px #000000;border-bottom:solid 1px #000000;'>
<td style='width:5%;text-align:center; border-right:solid 1px #000000;border-bottom:solid 1px #000000;padding:3px 5px 3px 5px;font-size:12px;'>SN.</td>
<td style='width:45%;text-align:center; border-right:solid 1px #000000;border-bottom:solid 1px #000000;padding:3px 5px 3px 5px;font-size:12px;'>Description of Services</td>
<td style='width:13%;text-align:center; border-right:solid 1px #000000;border-bottom:solid 1px #000000;padding:3px 5px 3px 5px;font-size:12px;'>Per</td>
<td style='width:10%;text-align:center; border-right:solid 1px #000000;border-bottom:solid 1px #000000;padding:3px 5px 3px 5px;font-size:12px;'>Quantity</td>
<td style='width:12%;text-align:center; border-right:solid 1px #000000;border-bottom:solid 1px #000000;padding:3px 5px 3px 5px;font-size:12px;'>Rate</td>
<td style='width:15%;text-align:center; border-bottom:solid 1px #000000;padding:3px 5px 3px 5px;font-size:12px;'>Amount in Rs.</td>
</tr>";
Step-4: check the loop condition
while(true)
{
Step-5: checking the iteration count
if($cnt>3)
{
$pageCount++;
break;
}
Step-6: Pulling data from details table
$query1 = $dbConnection->prepare("SELECT * FROM details WHERE DocNo=? AND DocNO_Index=?");
$query1->execute(array($dno,$index));
$rowCnt = $query1->rowCount();
while($rows1 = $query1->fetch())
{
$desg = $rows1['Item'];
$des = $rows1['Description'];
$Quantity = $rows1['Quantity'];
$Rate = $rows1['Rate'];
$per = $rows1['Per'];
$gross = $rows1['Gross'];
$SERVICE_TAX = $rows1['SERVICE'];
$SERVICE_TAX = ($SERVICE_TAX==null)? 0.0 : $SERVICE_TAX;
$SB_Tax = $rows1['SB_Tax'];
$SB_Tax = ($SB_Tax==null)? 0.0 : $SB_Tax;
$Krishi_Kalyan_Cess = $rows1['Krishi_Kalyan_Cess'];
$Krishi_Kalyan_Cess = ($Krishi_Kalyan_Cess==null)? 0.0 : $Krishi_Kalyan_Cess;
$ratetot = $ratetot + $Rate;
$subtotal = $subtotal + $gross;
if($cnt == 1 && $index > 1)
{
$body.= "<tr><td style='width:5%;border-right:solid 1px #000;padding:3px 5px 3px 5px;font-size:12px;'></td><td style='width:45%;border-right:solid 1px #000;padding:3px 5px 3px 5px;font-size:12px;'>Opening Balance</td><td style='width:13%;border-right:solid 1px #000;padding:3px 5px 3px 5px;font-size:12px;'></td><td style='width:10%;border-right:solid 1px #000;padding:3px 5px 3px 5px;font-size:12px;'></td><td style='width:12%;text-align:right;border-right:solid 1px #000;padding:3px 5px 3px 5px;font-size:12px;'>". number_format($ratetot - $Rate, 2)." /-</td><td style='width:15%;text-align:right;padding:3px 5px 3px 5px;font-size:12px;'>". number_format($subtotal-$gross, 2)." /-</td></tr>";
}
$body.= "<tr><td style='width:5%;height:90px;vertical-align:top;border-right:solid 1px #000;padding:3px 5px 3px 5px;font-size:12px;'>$index</td><td style='width:45%;height:90px;vertical-align:top; border-right:solid 1px #000;padding:3px 5px 3px 5px;font-size:12px;'>";
if($proj!=null)
$body.= "$proj<br/>";
if($desg!=null)
$body.= "$desg<br/>";
if($des!=null)
$body.= "$des<br/>";
if($projNo!=null)
$body.= "$projNo<br/>";
if($sermnth!=null)
$body.= "$sermnth<br/>";
$body.= "</td><td style='width:13%;height:90px;vertical-align:top;text-align:center; border-right:solid 1px #000000;padding:3px 5px 3px 5px;font-size:12px;'>$per</td><td style='width:10%;height:90px;vertical-align:top; border-right:solid 1px #000000;padding:3px 5px 3px 5px;text-align:center;;font-size:12px;'>$Quantity</td><td style='width:12%;height:90px;vertical-align:top;text-align:right; border-right:solid 1px #000000;padding:3px 5px 3px 5px;font-size:12px;'>". number_format($Rate,2)."/-</td><td style='width:15%;height:90px;vertical-align:top; padding:3px 5px 3px 5px; text-align:right;;font-size:12px;'>". number_format($gross,2)."/-</td></tr>";
if($cnt == 3 || $index == $noInvs)
{
$body.= "<tr><td style='width:5%;border-right:solid 1px #000;padding:3px 5px 3px 5px;font-size:12px;'></td><td style='width:45%;border-right:solid 1px #000;padding:3px 5px 3px 5px;font-size:12px;'>";
if($index != $noInvs)
{
$body.= "Closing Balance";
}
$body.= "</td> <td style='width:13%;border-right:solid 1px #000;padding:3px 5px 3px 5px;font-size:12px;'></td><td style='width:10%;border-right:solid 1px #000;padding:3px 5px 3px 5px;font-size:12px;'></td><td style='width:12%;border-right:solid 1px #000;border-top:solid 1px #000;text-align:right;padding:3px 5px 3px 5px;font-size:12px;'>". number_format($ratetot,2)."/-</td><td style='width:15%;border-top:solid 1px #000;text-align:right;padding:3px 5px 3px 5px;font-size:12px;'>". number_format($subtotal,2)."/-</td></tr>";
}
}
$index++;
$cnt++;
}
$body .= "</tbody></table></td></tr>";
$stax = round($subtotal*($SERVICE_TAX/100),2);
$sbc = round($subtotal*($SB_Tax/100),2);
$kkc = round($subtotal*($Krishi_Kalyan_Cess/100),2);
$grandtotal = round(($subtotal+$stax+$sbc+$kkc),2);
$rupee = number2word($grandtotal);
$body .="<tr><td valign='top' align='left' style='border-left: solid 1px #000000;border-right: solid 1px #000000;border-bottom: solid 1px #000000;;font-size:12px;'><table cellpadding='0' cellspacing='0' width='100%'><tr><td rowspan='2' style='width:50%;height:50px; border-right:solid 1px #000000;padding:3px 5px 3px 5px;font-size:12px;'>";
if($pageCount == $lastPage)
{
$body .= "<strong style='font-size:12px;'>Narration : </strong><br/>Amount in Words (Rupees):<br/>";
}
$body .= "<br/>$rupee";
$body .= "</td><td style='width:35%; border-bottom:solid 1px #000000;border-right:solid 1px #000000;padding:3px 5px 3px 5px;font-size:12px;'>";
if($pageCount==$lastPage)
{
$body .= "Sub Total : <br />Service Tax # 14% <br />Swachh Bharat Cess # 0.5% <br />Krishi Kalyan Cess # 0.5% <br />";
}
$body .= "</td><td style='width:15%;text-align:right; border-bottom:solid 1px #000000;padding:3px 5px 3px 5px;;font-size:12px;'>";
if($pageCount==$lastPage)
{
$body .= "". number_format($subtotal,2)."/-<br />".number_format($stax,2)."/-<br />".number_format($sbc,2)."/-<br />".number_format($kkc,2)."/-<br />";
}
$body .= "</td></tr><tr><td style='width:35%; border-right:solid 1px #000000;padding:3px 5px 3px 5px;font-size:12px;'>";
if($pageCount==$lastPage)
{
$body .= "Total Amount";
}
$body .= "</td><td style='width:15%;text-align:right; padding:3px 5px 3px 5px;font-size:12px;'>";
if($pageCount == $lastPage)
{
$body .= number_format($grandtotal,2)."/-";
}
$body .= "</td></tr></table></td></tr><tr><td valign='top' align='left' style='border-left: solid 1px #000000;border-right: solid 1px #000000;border-bottom: solid 1px #000000;;font-size:12px;'><table width='100%' cellpadding='0' cellspacing='0'>
<tbody>
<tr>
<td style='width:50%; padding:3px 5px 3px 5px;border-right:1px solid #000;font-size:12px;'>
<strong>Thank you</strong>
</td>
<td valign='bottom' align='center' style='width:50%; text-align:center;font-size:12px;'>
<strong>AUTHORISED SIGNATORY</strong>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
<p> </p></div>";
$body .= "<html><head><title>$ino</title><style type='text/css'>.main-container{display: block;} #media print{.main-container{display: block;}#page{size:portrait;margin:10px auto;padding:0}.main-container{page-break-after:always!important;}}</style><script language='javascript' type='text/javascript'>function PrintPage() { window.print(); } </script></head><body style='font-size: 12px ! important;'>$body</body></html><!-- onload='window.print()'-->";
echo "$body";
}
}
Issue is loop iteration.
My code output like this
Any suggestions on how to do this or to point me in the right direction would be greatly appreciated.
You're trying to re-use an active database connection. That doesn't work. You need two connections.
Specifically, you're in the process of reading a result set from a query on your connection,
$query = $dbConnection->prepare("some query");
$query->execute(array($fdcu,$tdcu));
while($rows = $query->fetch()) {
...
when you issue another query on the same $dbConnection ...
$qry = $dbConnection->prepare("another query");
$qry->execute(array($name));
You Can't Do That™ while the first query is still active. Open up and use a different connection for the queries issued from inside your loop.
I want to run a foreach loop inside a msgHTML on PHP Mailer to make the table td dynamic from array. Below is the latest code I have. I' am working on dreamweaver and it show that this code has errors, I don't know how to solve this issue.
<?php
$mail->Subject = "Vacancy No: " . $vacancy_no . " - " . $vacancy_title;
$mail->MsgHTML(
"
Some html and text goes here....
Below is the main part of this topic.
<u><strong>Referees & Contact</strong></u><br/>
<table width='100%' border='0' cellpadding='0' cellspacing='0' style='border: 1px solid #E2E2E2;'>
<tr style='background: #003e82; color: #FFF; font-weight: bold;'>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Name</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Position & Organization</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Phone Contact</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Email</td>
</tr>
"
?>
<?php
foreach($variable as $var){
?>
<tr>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Name</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Position & Organization</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Phone Contact</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Email</td>
</tr>
<?php
}
?>
<?php "
</table>
");
?>
How about this code?
$mail->Subject = "Vacancy No: " . $vacancy_no . " - " . $vacancy_title;
$msg = "Some html and text goes here....
Below is the main part of this topic.
<u><strong>Referees & Contact</strong></u><br/>
<table width='100%' border='0' cellpadding='0' cellspacing='0' style='border: 1px solid #E2E2E2;'>
<tr style='background: #003e82; color: #FFF; font-weight: bold;'>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Name</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Position & Organization</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Phone Contact</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Email</td>
</tr>";
foreach($variable as $var){
$msg .= "<tr>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Name</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Position & Organization</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Phone Contact</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Email</td>
</tr>";
} // foreach
$msg .= "</table>";
$mail->MsgHTML( $msg );
try this
$mail->Subject = "Vacancy No: " . $vacancy_no . " - " . $vacancy_title;
$message =
"
Some html and text goes here....
Below is the main part of this topic.
<u><strong>Referees & Contact</strong></u><br/>
<table width='100%' border='0' cellpadding='0' cellspacing='0' style='border: 1px solid #E2E2E2;'>
<tr style='background: #003e82; color: #FFF; font-weight: bold;'>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Name</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Position & Organization</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Phone Contact</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Email</td>
</tr>
";
foreach ($variable as $var) {
$message .= "<tr>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Name</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Position & Organization</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Phone Contact</td>
<td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Email</td>
</tr>";
}
$message .= "
</table>
";
$mail->MsgHTML($message);
I have to download the records from database into a word file. But m not able to do so as whenever i add while loop around the table it is giving me error.
My code is working fine when i fetch single records.
Can anbody provide me the way to fetch multiple records.
Here is my Code:
<?php
include('dbcon.php');
if($_GET['id']!='')
$id=$_GET['id'];
$party_name=mysql_query("select * FROM tb_party Where party_id='".$id."' ");
$party_name_row=mysql_fetch_array($party_name);
$sample_text1 = $party_name_row['party_name'];
$party_details="select * from tb_party_rate_entry
where party_id='$id'";
$query_details=mysql_query($party_details);
$row_details=mysql_fetch_array($query_details);
$word_xmlns = "xmlns:o='urn:schemas-microsoft-com:office:office'
xmlns:w='urn:schemas-microsoft-com:office:word'
xmlns='http://www.w3.org/TR/REC-html40′";
$word_xml_settings = "<xml><w:WordDocument>
<w:View>Print</w:View><w:Zoom>100</w:Zoom></w:WordDocument></xml>";
$word_landscape_style =
"#page {size:8.5in 11.0in; margin:0.5in 0.31in 0.42in 0.25in;
} div.Section1{page:Section1;}";
$word_landscape_headinh="{font-size:15px; }";
$word_landscape_div_imf='
<img src="http://silverevents.net/user_image/' .$sample_text1 . '"
height="150" width="150"/>';
$word_landscape_div_start = "<div class='Section1′>";
$word_landscape_div_end = "</div>";
$content = '<html '.$word_xmlns.'>
<head>
<title>Party Rate Report</title>'
.$word_xml_settings.'<style type="text/css">
'.$word_landscape_style.' table,td
{border:1px solid #FFFFFF; width:200px; color:#CCC;} </style>
</head>
<body>'.$word_landscape_div_start .
'<table style="width:500px; color:#000000;
margin:0 0 50px 100px; font-family: Arial Black, Gadget,
sans-serif; font-size:24px;"><tr><td> Party Rate Report </td>
</tr></table></br>
<table style="width:700px;font-size:15px;font-family:
Arial Black, Gadget, sans-serif;">
<tr>
<td width="180">
Party Name : '. $party_name_row['party_name'] . '
</td>
<td width="250">
Address : '. $party_name_row['party_address'] . '
</td>
<td width="150">
Phone : '. $party_name_row['phone_no']. '
</td>
</tr>
</table><br/>
<table style="width:700px; color:#00000; margin:22px 0 0 0px;
font- family:Helvetica, sans-serif, Verdana;
font-size:15px; border1px solid #666;">
<tr>
<td style=" border:1px solid #666; width:300px;"> Zone</td>
<td style=" border:1px solid #666; width:300px;">
Delivery Mode
</td>
<td style=" border:1px solid #666; width:300px;"> Doc Type </td>
<td style=" border:1px solid #666; width:300px;"> Weight slot </td>
<td style=" border:1px solid #666; width:300px;"> Weight Unit </td>
<td style=" border:1px solid #666; width:300px;"> Flat </td>
<td style=" border:1px solid #666; width:300px;"> Price </td>
</tr>
<tr>
<td style=" border:1px solid #666; width:300px;">' .
$row_details['zone_id']. '</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['delivery_mode_id'].'
</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['doc_type_id'].'</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['weight_slot_id'].'</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['weight_measure_id'].'</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['flat'].'</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['price' ] . '</td>
</tr>
</table></br>' . $word_xml_settings. $word_landscape_div_end.'
</body>
</html>';
#header('Content-Type: application/msword');
#header('Content-Length: '.strlen($content));
#header('Content-disposition: inline; filename="Party Rate Report.doc"');
echo $content;
?>
Here my database:
Quick reformat, adding a loop (and assuming the id is an integer):-
<?php
include('dbcon.php');
if($_GET['id']!='')
{
$id=intval($_GET['id']);
$party_name=mysql_query("select * FROM tb_party Where party_id=$id ");
if ($party_name_row=mysql_fetch_array($party_name))
{
$sample_text1 = $party_name_row['party_name'];
}
$word_xmlns = "xmlns:o='urn:schemas-microsoft-com:office:office'
xmlns:w='urn:schemas-microsoft-com:office:word'
xmlns='http://www.w3.org/TR/REC-html40'";
$word_xml_settings = "<xml><w:WordDocument>
<w:View>Print</w:View><w:Zoom>100</w:Zoom></w:WordDocument></xml>";
$word_landscape_style =
"#page {size:8.5in 11.0in; margin:0.5in 0.31in 0.42in 0.25in;
} div.Section1{page:Section1;}";
$word_landscape_headinh="{font-size:15px; }";
$word_landscape_div_imf='
<img src="http://silverevents.net/user_image/' .$sample_text1 . '"
height="150" width="150"/>';
$word_landscape_div_start = "<div class='Section1'> ";
$word_landscape_div_end = "</div>";
$content = '<html '.$word_xmlns.'>
<head>
<title>Party Rate Report</title>'
.$word_xml_settings.'<style type="text/css">
'.$word_landscape_style.' table,td
{border:1px solid #FFFFFF; width:200px; color:#CCC;} </style>
</head>
<body>'.$word_landscape_div_start .
'<table style="width:500px; color:#000000;
margin:0 0 50px 100px; font-family: Arial Black, Gadget,
sans-serif; font-size:24px;"><tr><td> Party Rate Report </td>
</tr></table></br>
<table style="width:700px;font-size:15px;font-family:
Arial Black, Gadget, sans-serif;">
<tr>
<td width="180">
Party Name : '. $party_name_row['party_name'] . '
</td>
<td width="250">
Address : '. $party_name_row['party_address'] . '
</td>
<td width="150">
Phone : '. $party_name_row['phone_no']. '
</td>
</tr>
</table><br/>
<table style="width:700px; color:#00000; margin:22px 0 0 0px;
font- family:Helvetica, sans-serif, Verdana;
font-size:15px; border1px solid #666;">
<tr>
<td style=" border:1px solid #666; width:300px;"> Zone</td>
<td style=" border:1px solid #666; width:300px;">
Delivery Mode
</td>
<td style=" border:1px solid #666; width:300px;"> Doc Type </td>
<td style=" border:1px solid #666; width:300px;"> Weight slot </td>
<td style=" border:1px solid #666; width:300px;"> Weight Unit </td>
<td style=" border:1px solid #666; width:300px;"> Flat </td>
<td style=" border:1px solid #666; width:300px;"> Price </td>
</tr>';
$party_details="select *
from tb_party_rate_entry
where party_id=$id";
$query_details=mysql_query($party_details);
while($row_details=mysql_fetch_array($query_details))
{
$content .= '<tr>
<td style=" border:1px solid #666; width:300px;">' .
$row_details['zone_id']. '</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['delivery_mode_id'].'
</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['doc_type_id'].'</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['weight_slot_id'].'</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['weight_measure_id'].'</td>
<td style=" border:1px solid #666; width:300px;">'.
(($row_details['flat'] != '') ? $row_details['flat'] : ' ').'</td>
<td style=" border:1px solid #666; width:300px;">'.
$row_details['price' ] . '</td>
</tr>';
}
$content .= '</table></br>' . $word_xml_settings. $word_landscape_div_end.'
</body>
</html>';
#header('Content-Type: application/msword');
#header('Content-Length: '.strlen($content));
#header('Content-disposition: inline; filename="Party Rate Report.doc"');
echo $content;
}
?>
Note for new code you probably should switch to using mysqli rather than the php mysql drivers
do something like this:
while ($row_details=mysql_fetch_array($query_details)) {
//do row specific code
}