DOMPDF not open in Windows - php

I have made a PDF document from PHP, but I do not open in Microsoft Widnows 7 and 8, It has made the PDF with tables, and insert the data correctly with cycles, but in Windows this problem occurs and does not open the downloaded PDF document, I've done the test with 3 computers with Windows.
public function pdfAction() {
require_once("dompdf/dompdf_config.inc.php");
$seguimiento = new Application_Model_DbTable_Seguimientos();
$datos_seguimiento = $seguimiento->casosReportes();
//var_dump($datos_seguimiento);
for ($i = 0; $i < count($datos_seguimiento); $i++) {
$caso = new Application_Model_DbTable_AsuntosEstudiantiles();
.........continuecode...................
$html = '<html><body>' .
'<table border="1" rules="all">
<tr>
<th colspan="10"> TITLE</th>
</tr>
<tr>
<td>Periodo Academico</td>
<td>ESTAMENTO (Estudiante, Profesor, administrativo)</td>
<td>Nombre</td>
<td>GENERO (Femenino - Masculino)</td>
<td>TIPO DE INDENT(c.c. - t.i. - c.ext.)</td>
<td>NUMERO DE IDENT</td>
<td>Codigo</td>
<td>PROYECTO CURRICULAR o DEPENDENCIA</td>
<td>FACULTAD</td>
<td>Tipo Caso</td>
<td>Observaciones</td>
</tr>';
$datoshtml = $datoshtml . '
<tr>
<td>' . $fecha . '</td>
<td>' . $tipo_beneficiario . '</td>
<td>' . $nombre_beneficiario . '</td>
<td>' . $genero . '</td>
<td>' . $tipo_identificacion . '</td>
<td>' . $numero_identificacion . '</td>
<td>' . $codigo_ud . '</td>
<td>' . utf8_decode($nombre_proyecto) . '</td>
<td>' . utf8_decode($nombre_facultad) . '</td>
<td>' . $tipoasunto . '</td>
<td>' . utf8_decode($observaciones) . '</td>
</tr>';
/* */
}
$html1 = '</table></font></body></html>';
$info = $html . $datoshtml . $html1;
//echo $info;
$dompdf = new DOMPDF();
$dompdf->set_paper("A4", "landscape");
$dompdf->load_html($info);
$dompdf->render();
$dompdf->stream("reporte.pdf");
}
Open in Linux
Open in Windows

Related

My code is outputting all data in 1 row, how do i make it output seperate data into seperate rows?

When my data is outputted from my server onto a website it outputs it onto 1 row instead of going down a row and outputting the next row of data
!
session_start();
$view = new stdClass();
$view->pageTitle = 'Camp Sites';
require_once('views/CampSites.phtml');
require_once('Models/campData.php');
require_once('Models/campDataSet.php');
$campDataSet = new campDataSet();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$search = $_POST['search'];
$_SESSION['search'] = $search;
$sqlQuery = "SELECT * FROM campsites ='$search'";
$result = $campDataSet->fetchAllCamps($sqlQuery);
if (count($result) > 0) {
echo'<div class="table-responsive">
<table class="table">
<thead id="table1Head">
<tr><td>campID</td>
<td>Name</td>
<td>Address</td>
<td>Postcode</td>
<td>Country</td>
<td>Latitude</td>
<td>Longitude</td>
<td>email</td>
<td>Phone<td></tr>
</thead>
<tbody>
</div>';
foreach ($result as $row) {
echo '<td>' . $row->id_campsite. '</td> <td>' . $row->campsite_name . '</td> <td>' . $row->address . '</td> <td>' . $row->postcode . '</td> <td>' . $row->country. '</td> <td>' . $row->lattitude . '</td> <td>' . $row->longitude . '</td> <td>' . $row->email . '</td> <td>' . $row->phone_number . '</td> </td>';
}
echo "</tbody></table>";
} else {
print " 0 results";
}
}
if (count($result) > 0) {
echo'<div class="table-responsive">
<table class="table">
<thead id="table1Head">
<tr><td>campID</td>
<td>Name</td>
<td>Address</td>
<td>Postcode</td>
<td>Country</td>
<td>Latitude</td>
<td>Longitude</td>
<td>email</td>
<td>Phone<td></tr>
</thead>
<tbody>
</div>';
foreach ($result as $row) {
echo '<tr><td>' . $row->id_campsite. '</td> <td>' . $row->campsite_name . '</td> <td>' . $row->address . '</td> <td>' . $row->postcode . '</td> <td>' . $row->country. '</td> <td>' . $row->lattitude . '</td> <td>' . $row->longitude . '</td> <td>' . $row->email . '</td> <td>' . $row->phone_number . '</td> </td></tr>';
}
echo "</tbody></table>";
} else {
print " 0 results";
}
You need to wrap tags around the code in your foreach like above.

Why is the button not working only for the first row nor it posting any value?

I am presently working on a project in php mysql to display content from db with edit option against each row. In the below is the code, I am not able to return any value only for the first row, Rest of the row buttons are working fine. I am not able to figure out what is issue. It would be great if you could help me out.
Code snippet of the table display page
$sql1 = "SELECT * FROM `computation` WHERE `compute_month` = '$month' and `compensation_type` = '$allowance' and order by `emp_id` ASC";
}
$result1 = mysqli_query($con, $sql1);
echo "
<form action='confirmallowance.php' method='POST'>
<table class=data-table border='1' overflow-x=auto>
<caption class=title><b>Allowance Sheet<b></caption>
<thead>
<tr>
<th>Date</th>
<th>Allowance Month</th>
<th>Attendance Date</th>
<th>Day</th>
<th>Employee Code</th>
<th>Employee Name</th>
<th>InTime</th>
<th>OutTime</th>
<th>Work Duration</th>
<th>Team</th>
<th>Approver</th>
<th>Allowance type</th>
<th>Eligibility</th>
<th>Approved_amount</th>
<th>Status</th>
</tr>
</thead>
<tbody>";
if (mysqli_num_rows($result1) > 0) {
// output data of each row
while ($row = mysqli_fetch_assoc($result1)) {
echo '
<tr id="' . $row['id'] . '">
<td>' . $row['computation_date'] . '</td>
<td>' . $row['compute_month'] . '</td>
<td>' . $row['attendance_date'] . '</td>
<td>' . $row['attend_day'] . '</td>
<td>' . $row['emp_id'] . '</td>
<td>' . $row['emp_name'] . '</td>
<td>' . $row['time_in'] . '</td>
<td>' . $row['time_out'] . '</td>
<td>' . $row['duration'] . '</td>
<td>' . $row['team'] . '</td>
<td>' . $row['manager'] . '</td>
<td>' . $row['compensation_type'] . '</td>
<td>' . $row['eligibility'] . '</td>
<td>' . $row['amount'] . '</td>
<td>' . $row['status'] . '</td>
<td><input type="checkbox" name="checkbox[]" value="' . $row['id'] . '" checked="checked"></td>
<td>
<form action="editallowance.php" method="POST"><input type="hidden" name="tempid"
value="' . $row['id'] . '"/><input type="submit"
name="submit"
value="Edit"/>
</form>
</td>
</tr>
';
}
}
// Code snippet of the table value acceptance page on edit button click
if (isset($_POST["submit"]) && $_POST["submit"]) {
$editrow = $_POST['tempid'];
$sql = "SELECT * FROM `computation` WHERE `id` ='$editrow'";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$att_date = $row['attendance_date'];
$att_day = $row['attend_day'];
$emp_id = $row['emp_id'];
$emp_name = $row['emp_name'];
$comptype = $row['compensation_type'];
$eligibility = $row['eligibility'];
$comment = $row['comment'];
$status = $row['status'];
echo "<P>Emp ID : " . $emp_id . "</p> <p>Emp Name :" . $emp_name . "</p><p>Attendance Date : " . $att_date . "</p><p>Day : " . $att_day . "</p>";
}
}
} else {
echo "No data";
If you need any addition info, please let me know.
Your html is not well formed. You are adding unused form open tag before table opening tag (there is not closing tag of it as well) in the first file:
<form action='confirmallowance.php' method='POST'>
<table class=data-table border='1' overflow-x=auto>
Please remove this form open tag html and it will work fine. It is interfering with the html forms that come later.

Two values in the same column

I have two columns with different values:
And I need to echo those two values into one column, like that:
Printing method:
if($result->num_rows > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo '<tr>
<td scope="row">' . $row["id"].'</td>
<td>' . $row["data"] .'</td>
<td>' . $row["ip"] .'</td>
</tr>';
}
}
Any suggestions on how I could do that?
Do you mean like this
echo '<tr>
<td scope="row">' . $row["id"].'</td>
<td>' . $row["data"] . '(' . $row["ip"] . ')</td>
</tr>';
Merge the two cells:
<td>' . $row["data"] .'</td>
<td>' . $row["ip"] .'</td>
Into one:
<td>' . $row["data"] . '(' . $row["ip"] . ')</td>

php change rows color with same value

I have a page which displays some data imported in MySQL database from Excel file
I want to change background color of rows with same values (grouped) on col "Billing Doc" like this picture:
Here is a part of my php code:
<form action="uploadExcel.php" method="POST" enctype="multipart/form-data">
<div>
<input type="file" name="file">
<input type= "submit" value ="Upload" >
</div>
</form>
<table width="100%" border="1" cellpadding="5">
<tr>
<th>ID</th>
<th>Billing Doc</th>
<th>Invoice Date</th>
<th>Ordered Parts</th>
<th>Shipped Parts</th>
<th>Qty</th>
<th>F</th>
<th>G</th>
<th>Amount</th>
<th>Delivery No</th>
<th>D/O Creation Date</th>
<th>Description</th>
<th>P/O No</th>
<th>Ship-to</th>
<th>Tracking No</th>
<th>Obs</th>
</tr>
<?php
while ($row = $result->fetch_object()) {
if (substr( $row->tracking_no, 0, 3 ) === "534") {
$row->tracking_no = "<a href='http://www.dhl.be/en/express/tracking.html?pageToInclude=RESULTS&AWB=$row->tracking_no&type=fasttrack' title='DHL'>$row->tracking_no</a>";
}
if (substr( $row->tracking_no, 0, 3 ) === "730") {
$row->tracking_no = "<a href='http://www.tnt.com/webtracker/tracker.do?navigation=1&respLang=en&respCountry=gb&cons=$row->tracking_no' title='TNT'>$row->tracking_no</a>";
}
$colour = '';
echo '
<tr style="background-color:' .$colour. '">
<td>' . $row->id_factura . '</td>
<td>' . $row->billing_doc . '</td>
<td>' . $row->invoice_date . '</td>
<td>' . $row->ordered_parts . '</td>
<td>' . $row->shipped_parts . '</td>
<td>' . $row->qty . '</td>
<td>' . number_format($row->F, 2) . '</td>
<td>' . number_format($row->G, 2) . '</td>
<td>' . number_format($row->amount, 2) . '</td>
<td>' . $row->delivery_no . '</td>
<td>' . $row->d_o_creation_date . '</td>
<td>' . $row->description . '</td>
<td>' . $row->po_no . '</td>
<td>' . $row->ship_to . '</td>
<td>' . $row->tracking_no . '</td>
<td>' . $row->obs . '</td>
</tr>
';
}
?>
</table>
It seems that the only variable to consider is Billing Doc, if so, inside your while loop use an array to store the billing id as a key and then check every value to see if the key already exists then print the color you want to:
$billing_docs = [];
while ($row = $result->fetch_object()) {
echo '<tr style="background-color:' . (array_key_exists($row->id_factura, $billing_docs) ? '#666' : '#DDD') . '">...';
$billing_docs[$row->id_factura] = '';
}
You could create a variable with the first billing_doc value: $billing = $row->billing_doc and use an if else to echo the same color row if the $billing_doc value is the same. The else would declare the new color variable and echo rows of that color.

Error in the exported excel file

This is error appears when I try to open the exported file, when I click yes the file opens but has error above the table:
<?php require '../backend/dbcon.php';
$query=mysql_query( "SELECT * FROM membership");
$total=mysql_num_rows($query);
if ($total>0) { $output .= '
<table border="1">
<tr>
<th>NO</th>
<th>Names</th>
<th>Email</th>
<th>Phone</th>
<th>Amount(N$)</th>
<th>Payment</th>
</tr>'; while ($row = mysql_fetch_array($query)) { $output .= '
<tr>
<td>' . $row["id"] . '</td>
<td>' . $row["names"] . '</td>
<td>' . $row["personal_email"] . '</td>
<td>' . $row["personal_phone"] . '</td>
<td>' . 110 . '</td>
<td>' . $row["payment"] . '</td>
</tr>
'; } $output .= '
</table>';
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=Membe.xls"); echo $output; }

Categories