I am, once again, having problems with PHP.
I working on a PDF where i have to show a image that also appears in the webpage.
The problem is that the image doesn't show on the PDF.
In fact it is a different kind of image, it is actually more like a chart.
Everything you do in the webpage is shown in the chart and i have to print it in the PDF, but the PDF simply ignores the print command.
Example of the code in HTML(which works just fine):
<html>
<h3>
you can take files copies in xls or Pdf format
</h3>
<br> Generate excel file <br> <BR>
<form method="post" action="" target="_blank">
<input type="submit" name="pdf" value="generate PDF " />
<input type="hidden" id="hide" name="hide">
</form><br>
<center><div id="image" name="image"><img src="../useful/createchart.php"/></div> </center>
</html>
as you can see it is used a PHP file to create the chart(which is not exactly a class, it just a PHP file with some methods).
So i am kind of clueless on what i have t do to the image be displayed in the PDF.
BTW I'm working with mPDF.
And here i have part of hte code to print the PDF, thats the part that matters. it prints the tables just fine but it simply doesn't print the image.
<?php // create PDF report ...
if (isset($_POST['pdf'])){
$mpdf = new mPDF();
//foreach ($showmore as $items){
$array = explode('-', $store);
//$Result = array();
foreach ($array as $member){
if($member != '')
$res= $dao->getinfobynumber ('jc', $member);
//var_dump($res);
foreach ($res as $jcvalue){
$mpdf->SetHeader("Tabela");
$mpdf->SetFooter(date('l jS \of F Y h:i:s A'));
$htmlpdf2 .= "
<table border='1'>
<tr>
<th width='150'>GE</th>
<td width='200'>". $jcvalue->getsg()."</td>
<td width='200'><strong>Nome Curto</strong></td>
<td width='200'>". $jcvalue->getnomecurto()."</td>
</tr>
</table>
<table border='1'>
<tr>
<th width='150'>Valor</th>
<td width='200'>". $jcvalue->getpvalor() ."</td>
<td width='200'><strong>FC</strong></td>
<td width='200'>". $jcvalue->getfc() ."</td>
</tr>
</table>
<table border='1'>
<tr>
<th width='150'> Jugular </th>
<td width='117'>". $jcvalue->getjugular1() ."</td>
<td width='117'>". $jcvalue->getjugular2() ."</td>
<td width='117'>". $jcvalue->getjugular3() ."</td>
<td width='118'>". $jcvalue->getjugular4() ."</td>
<td width='119'>". $jcvalue->getjugular5() ."</td>
</tr>
</table>
<table border='1'>
<tr>
<th width='150'>EXP3D</th>
<td width='200'>". $jcvalue->getd3_1() ."</td>
<td width='200'>". $jcvalue->getd3_2() ."</td>
<td width='200'>". $jcvalue->getd3_3() ."</td>
</tr>
</table>
<table border='1'>
<tr>
<th width='150'>EXP28D</th>
<td width='200'>". $jcvalue->getd28_1() ."</td>
<td width='200'>". $jcvalue->getd28_2() ."</td>
<td width='200'>". $jcvalue->getd28_3() ."</td>
</tr>
</table>
<table border='1'>
<tr>
<th width='150'>Carotida</th>
<td width='303'>". $jcvalue->getcarotida_1() ."</td>
<td width='303'>". $jcvalue->getcarotida_2() ."</td>
</tr>
</table>
<br><br>";
}
}
$PDFimage = "<center><div id='image' name='image'><img src='../useful/createchart.php'/></div></center>";
$mpdf->WriteHTML($htmlpdf2);
$mpdf->WriteHTML($PDFimage);
$mpdf->Output();
}
here is the code to use the web page to select what you want to see and the apge chows you all the data it has avaiable from what you selected + the chart based on the data:
<?php session_start();
//this file contains the full information for the sample
// will include in this file simple table contains all informations
// also will calling function from creat table and also will call function create chart and export to excel
require_once '../useful/createtable.php';
require_once '../dao/bancojc_424_dao.php';
require_once '../model/jcdrow.php';
require_once '../model/jc.php';
include("../useful/MPDF57/MPDF57/mpdf.php");
require_once '../dao/meta.php';
?>
<?php
$table = new createtable();
$dao = new daobancojc();
$meta = new metachart();
$meta->resetmeta();
$showmore =explode('-', $_GET['data']);
$showtable =explode('-', $_GET['table']);
$t='';
$htmlpdf='';
foreach($showmore as $item ){
if ($item !=''){
foreach($showtable as $tables)
if($tables == 'jc')
{
$result=$dao->getinfobynumber ('jc', $item);
$t='jc';
}elseif ($tables == 'j3d'){
$result=$dao->getinfobynumber ('j3d', $item);
$t='j3d';
}elseif($tables == 'j28d'){
$result=$dao->getinfobynumber ('j28d', $item);
$t='j28d';
}
$store .= '';
foreach ($result as $return){
$meta->insertmeta($t,$return->getsg());
$htmlpdf= 'No:'.$return->getsg(). '<br>';
$htmlpdf.= 'Nome Curto: '.$return->getnomecurto().' Nome Longo : ';
$htmlpdf.= $return->getnomelongo();
echo $htmlpdf;
?>
<table class="tabela_registros1" border=1 width=80% ><?php
$htmlpdf.= $table->morejc($return);
echo $htmlpdf;
?>
</table> <?php $store .= '-'.$return->getsg() ;
}
Related
I need to place a button that says "Yes", but I need that when clicking on the button take the user to a web page, here is the php code for them to review:
<table cellpadding="1" cellspacing="1" id="member">
<thead>
<tr>
<th colspan="10">Players Not Activated</th>
</tr>
<tr>
<td class="on">#</td>
<td class="on">ID</td>
<td class="on">Username</td>
<td class="on">Email</td>
<td class="on">Tribe</td>
<td class="on">Activation Code</td>
<td class="on">Act 2??</td>
<td class="on">Time</td>
<td class="on">PLAY</td>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM ".TB_PREFIX."activate";
$result = mysqli_query($GLOBALS["link"], $sql);
while($row = mysqli_fetch_assoc($result))
{
$i++;
if($row['tribe'] == 1) {$tribe = "Roman"; }
elseif($row['tribe'] == 2) {$tribe = "Teuton"; }
elseif($row['tribe'] == 3) {$tribe = "Gaul"; }
echo "
<tr>
<td>".$i."</td>
<td>".$row['id']."</td>
<td>".$row['username']."</td>
<td>".$row['email']."</td>
<td>".$tribe."</td>
<td>".$row['act']."</td>
<td>".$row['act2']."</td>
<td class=\"hab\">".date('d:m:Y H:i', $row['timestamp'])."</td>
</tr>";
}
?>
</tbody>
</table>
I need the button to appear where it says "PLAY"
and the destination url i want is this link:
<a href="activate.php?id=<?php echo $_GET['id']; ?>
I have tried 4 days ago to be able to make it work but whenever I modify the file I receive a blank error page.
i have table html code in a var like
$table = "<table style="width: 100%">
<tr>
<td>Name</td>
<td>Age</td>
</tr>
<tr>
<td>Mark</td>
<td>30</td>
</tr>
</table>
";
is there a way to edit it in a simple textarea editor (without toolbar) but Does not appear like a source code , appear like design or templat and Then I will save it with a database with php form .
<textarea id="textarea_editor"><?php echo $table; ?></textarea>
Example :
"<" replace "<" and ">" replace ">"
<?
$table = "<table style=\"width: 100%\">
<tr>
<td>Name</td>
<td>Age</td>
</tr>
<tr>
<td>Mark</td>
<td>30</td>
</tr>
</table>
";
$tab = str_replace(str_replace($table, "<", "<") , ">" ,">");
?>
<textarea id="textarea_editor"><?php echo $table; ?></textarea>
I have a program that insert many records and image to a database. I must display my records and image into the web page (forms-output.php) but only 4 records and images. If I click the link (example: link in the ref_code) and records and image must display into a new web page (forms-full-data.php) but only records and image when I click what to display. Almost all work has been completed, but when I click a field in the ref_code all records have been successfully displayed except the images. Can you help me please?
This is forms-output.php:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "profil";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo '
<div class="table-responsive">
<table class="table table-bordered table-striped mb-none" id="datatable-tabletools" data-swf-path="assets/vendor/jquery-datatables/extras/TableTools/swf/copy_csv_xls_pdf.swf">
<thead>
<tr align="center" bgcolor="#E9E9E9">
<td align="center" width="1"><b>No</td>
<td width="10%" align="center"><b>Photo</td>
<td width="100" align="center"><b>Ref Code</td>
<td width="100" align="center"><b>Name</td>
<td width="100" align="center"><b>Date</td>
</tr>
<tr>';
$no = 1; //inisialisasi untuk penomoran data
$sql= "SELECT image, name, ref_code, image, overseas, avaibility, sector, country, date, height, weight, religion, status, children, education, language, language2, experience1, experience2, experience3, experience4, experience5, other1, other2, other3, other4, other5, other6, working_experience, working_experience2, working_experience3, working_experience4, working_experience5 FROM tb_profil";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$gambar="<img src='images/" . $row["image"] . "' width='200'" . "' height='150' ></td><td align='center'>";
$data="<b>$row[name]<br><br>$row[ref_code]<br><br>$row[overseas]<br><br>$row[avaibility]<br><br>$row[sector]<br><br>$row[country]<br><br>$row[date]<br><br>$row[height]<br><br>$row[weight]<br><br>$row[religion]<br><br>$row[status]<br><br>$row[children]<br><br>$row[education]<br><br>$row[language]<br><br>$row[language2]<br><br>$row[experience1]<br><br>$row[experience2]<br><br>$row[experience3]<br><br>$row[experience4]<br><br>$row[experience5]<br><br>$row[other1]<br><br>$row[other2]<br><br>$row[other3]<br><br>$row[other4]<br><br>$row[other5]<br><br>$row[other6]<br><br>$row[working_experience]<br><br>$row[working_experience2]<br><br>$row[working_experience3]<br><br>$row[working_experience4]<br><br>$row[working_experience5]$row[image]";
echo "<tr><td align='center'>" .$no. "</td><td>$gambar<a href='forms-full-data.php?p=$data'>" . $row["ref_code"] . "</td><td align='center'>" . $row["name"] . "</td><td align='center'>" . $row["date"] . "</td></tr>";
$no++;
}
echo "</table>";
} else {
echo "0 results";
}
?>
This is forms-full-data.php:
<?php
// server info
$host = 'localhost';
$user = 'root';
$password = '';
$database_name = 'profil';
$mysqli = new mysqli($host, $user, $password, $database_name);
$res = $mysqli->query("SELECT * FROM tb_profil WHERE ref_code='" . $_GET['p']."'");
$row = $res->fetch_assoc();
$gambar="<img src='images/" . $row["image"] . "' width='150'" . "' height='200' >";
if (isset($_GET['p'])) {
echo "<table width='100%' border='0'>
<tr>
<td rowspan='31' width='20'>
<td width='180'>Full Name</td>
<td rowspan='15' width='230'> </td>
<td rowspan='31' width='200'>$_GET[p]</td>
<td rowspan='5' width='200'>$gambar</td>
</tr>
<tr>
<td>Ref Code</td>
</tr>
<tr>
<td>Overseas Experience</td>
</tr>
<tr>
<td>Avaiability</td>
</tr>
<tr>
<td>Sector</td>
</tr>
<tr>
<td>Country</td>
</tr>
<tr>
<td>Date Of Birth</td>
</tr>
<tr>
<td>Height</td>
<td></td>
</tr>
<tr>
<td>Weight</td>
<td rowspan='17'> </td>
</tr>
<tr>
<td>Religion</td>
</tr>
<tr>
<td>Marital Status</td>
</tr>
<tr>
<td>Children</td>
</tr>
<tr>
<td>Education</td>
</tr>
<tr>
<td>Language</td>
</tr>
<tr>
<td>More Language</td>
</tr>
<tr>
<td rowspan='5'>Experience</td>
<td width='10'>Care For Children</td>
</tr>
<tr>
<td>Cooking</td>
</tr>
<tr>
<td>Care For Infant</td>
</tr>
<tr>
<td>Care For Newborn</td>
</tr>
<tr>
<td>Care For Elderly</td>
</tr>
<tr>
<td rowspan='6'>Other Information</td>
<td>Able To Handle Pork?</td>
</tr>
<tr>
<td>Able To eat Pork?</td>
</tr>
<tr>
<td>Able to care for dog/cat?</td>
</tr>
<tr>
<td>Able to swim?</td>
</tr>
<tr>
<td>Willing to lock after elderly forbidden?</td>
</tr>
<tr>
<td>Willing to work with no off days?</td>
</tr>
<tr>
<td>Working Experience</td>
<td rowspan='5'></td>
</tr>
<tr>
<td>More Working Experience 2</td>
</tr>
<tr>
<td>More Working Experience 3</td>
</tr>
<tr>
<td>More Working Experience 4</td>
</tr>
<tr>
<td>More Working Experience 5</td>
</tr>
</table>";
}
?>
Add '/', before 'images' catalog, while You build path.
Please read about 'SQL injection".
Please use ADODB to manage DB.
I have an html table like this
<table>
<tbody>
<tr>
<td><table>
<tbody>
<tr class="prdLi">
<td rowspan="2" class="prdNo"><span>310.</span></td>
<td colspan="2" class="prdDe" rowspan="2"><span>Pepsi</span></td>
</tr>
<tr class="prdLi">
<td class="prdAc"><span> 1.5L</span></td>
<td><span> </span></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
the table is saved as $html
I want to select the child elements of the class .prdLi
I tried like this:
foreach($html->find('tr.prdLi') as $foo){
echo $foo;
}
the output that i get is like this
<span>310.</span>
<span>Pepsi</span
.
.
.
but what i actually want to get is the code with the parent element td.like this:
<td rowspan="2" class="prdNo"><span>310.</span></td>
<td colspan="2" class="prdDe" rowspan="2"><span>Pepsi</span></td>
.
.
.
please help me
Since Simple HTML DOM Parser supports CSS like selectors, you can use 'tr.prdLi td' to specify all td elements which are children of tr with class prdLi. The following should provide what you are looking for:
$htmlstr = <<<EOD
<table>
<tbody>
<tr>
<td><table>
<tbody>
<tr class="prdLi">
<td rowspan="2" class="prdNo"><span>310.</span></td>
<td colspan="2" class="prdDe" rowspan="2"><span>Pepsi</span></td>
</tr>
<tr class="prdLi">
<td class="prdAc"><span> 1.5L</span></td>
<td><span> </span></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
EOD;
$html = str_get_html($htmlstr);
foreach ($html->find('tr.prdLi td') as $foo) {
echo $foo . "\n";
}
Note that find() is called on the main simple_html_dom-element. In your example, the result was already limited by a previous find().
What andy says is correct, but the css for direct child is > *, therefore:
foreach($html->find('tr.prdLi > *') as $foo){
echo $foo . "\n";
}
MSSQL query link is this;
click here for picture
and my output shows three different pictures for the same product as shown below. What I want is, if the product is the same, keep just one picture and then get the colors and sizes for that product.
Means;
My output ıs the picture below,
click here for picture
as you see there are three product in the picture but they are the same product with different colors and sizes, instead of seeing the same product every time, I want my output like in the picture below.
<table width="376" cellspacing="0" class="stats" width:100%>
<tr>
<td colspan="9" align="center"><?php echo $secim ?></td>
</tr>
<?php
while(odbc_fetch_into($sql_result, &$row)) {
$unit1 = floor($row[3]);
$unit2 = floor($row[4]);
$unit3 = floor($row[5]);
$unit4 = floor($row[6]);
$unit5 = floor($row[7]);
?>
<tr>
<td colspan="2" align="left" valign="top"><?php echo"$row[0]";?></td>
<td>36</td>
<td>38</td>
<td>40</td>
<td>42</td>
<td>44</td>
</tr>
<tr>
<td width="114" align="right" valign="top">
<img src= <?php echo"images/Resize/$row[2]"?>></td>
<td width="25" valign="top"><?php echo"$row[1]";?></td>
<td width="25"valign="top"><?php echo"$unit1";?></td>
<td width="25"valign="top"><?php echo"$unit2";?></td>
<td width="25"valign="top"><?php echo"$unit3";?></td>
<td width="25"valign="top"><?php echo"$unit4";?></td>
<td width="25"valign="top"><?php echo"$unit5";?></td>
</tr>
<?php } }?>
<?php
odbc_free_result($sql_result);
odbc_close($connection);
?>
</table>
I think this is what you are looking for, http://jsfiddle.net/sv8ZS/
while(odbc_fetch_into($sql_result, &$row)) {
$unit1 = floor($row[3]);
$unit2 = floor($row[4]);
$unit3 = floor($row[5]);
$unit4 = floor($row[6]);
$unit5 = floor($row[7]);
?>
//you can check with the index to see if its a first row or not
//This will avoid printing the same header for each row.
if (this-is-the-first row) {
<tr>
<td colspan="2" align="left" valign="top"><?php echo"$row[0]";?></td>
<td>36</td>
<td>38</td>
<td>40</td>
<td>42</td>
<td>44</td>
</tr>
}
//above if ends
<tr>
//If its not a first row then do not show the image again and merge all the next rows
if (this-is-the-first-row) {
<td width="114" align="right" valign="top" rowspan='3'>
<img src= <?php echo"images/Resize/$row[2]"?>
</td>
}
//above if ends
<td width="25" valign="top"><?php echo"$row[1]";?></td>
<td width="25"valign="top"><?php echo"$unit1";?></td>
<td width="25"valign="top"><?php echo"$unit2";?></td>
<td width="25"valign="top"><?php echo"$unit3";?></td>
<td width="25"valign="top"><?php echo"$unit4";?></td>
<td width="25"valign="top"><?php echo"$unit5";?></td>
</tr>
<?php } }?>
enter code here
<?php
echo "<table border='1'>
<tr>
<th>Model</th>
<th>Color</th>
<th>Unit</th>
</tr>";
?>
<?php
while($row =odbc_fetch_array($result)){
//if $row['sAciklama']=$row['sAciklama'] bla bla ???
if (this-is-the-first row) {
echo "<tr>";
echo "<td>" . $row['sAciklama'] . "</td>"; //Model First Element
}
if (this-is-the-first-row) {
echo "<td>" . $row['sRenkAdi'] . "</td>"; //color
echo "<td>" . $row['Kalan'] . "</td>"; //unit
echo "</tr>";
}}
echo "</table>";
?>