i have a huge table in my php page that contains alot of php coding inside it
i want to export it using tcpdf
the example in samples of thier website prints html as a variable and export it like that
$tbl = <<<EOD
<table cellspacing="0" cellpadding="1" border="1">
<tr>
<td rowspan="3">COL 1 - ROW 1<br />COLSPAN 3</td>
<td>COL 2 - ROW 1</td>
<td>COL 3 - ROW 1</td>
</tr>
<tr>
<td rowspan="2">COL 2 - ROW 2 - COLSPAN 2<br />text line<br />text line<br />text line<br />text line</td>
<td>COL 3 - ROW 2</td>
</tr>
<tr>
<td>COL 3 - ROW 3</td>
</tr>
</table>
EOD;
my table has many many sql and php coding ,,,,etc
any php code i put inside it not appeared on output
how to print it?
and here is my table i want to print
<table class="table" width="95%">
<tbody>
<tr >
<td width="20" class="tabletop">م</td>
<td class="tabletop" >name</td>
<td class="tabletop" style="width:120px">date</td>
<td class="tabletop" style="width:120px">note1</td>
<td class="tabletop" style="width:100px">note2</td>
<td class="tabletop" style="width:90px">note3</td>
</tr>
<? $res=mysql_query($sql);
while($resArr=mysql_fetch_array($res)){ ?>
<tr style="width:700px">
<td class="tabletext"><?= ++$serial;?></td>
<td class="tabletext" ><?= $resArr[stName];?></td>
<td class="tabletext"><?= $resArr['date'];?></td>
<td class="tabletext" ><?= $resArr[matName];?></td>
<td class="tabletext" ><? if($resArr[exam]==1) echo "work";else echo "final";?></td>
<td class="tabletext" ><? if($resArr[exam_type]==1) echo "prac";else echo "test";?></td>
</tr>
<? }?>
</tbody>
</table>
<?php
$print = '<table class="table" width="95%">
<tbody>
<tr >
<td width="20" class="tabletop">م</td>
<td class="tabletop" >name</td>
<td class="tabletop" style="width:120px">date</td>
<td class="tabletop" style="width:120px">note1</td>
<td class="tabletop" style="width:100px">note2</td>
<td class="tabletop" style="width:90px">note3</td>
</tr>';
$res = mysql_query($sql);
while ( $resArr = mysql_fetch_array($res) ){
$print .= '
<tr style="width:700px">
<td class="tabletext">'.$serial.'</td>
<td class="tabletext" >'.$resArr['stName'].'></td>
<td class="tabletext">'.$resArr['date'].'></td>
<td class="tabletext" >'.$resArr['matName'].'></td>
<td class="tabletext">';
if($resArr['exam']==1){
$print .= 'work';
}else{
$print .= 'final';
}
$print .= '</td><td class="tabletext" >';
if($resArr['exam_type']==1){
$print .= "prac";
}else{
$print .= "test";
}
$print .= '</td></tr>';
}
$print .= '</tbody></table>';
then simply use the variable $print
Related
Just want to display html table with TCPDF but getting errors instead.
Here is my code:
$tbl = <<<EOD
<table cellspacing="0" cellpadding="1" border="1">
<tr>
<td >
aaaaa
</td>
<td colspan="2" rowspan="2" >
bbbb
</td>
</tr>
<td rowspan="2">
hhhhh
</td>
</tr>
<tr>
<td>
iiii
</td>
<td>
jjjj
</td>
</tr>
</table>
EOD;
But when I replace my html table code with following html table code (from TCPDF examples), it displays correctly:
$tbl = <<<EOD
<table cellspacing="0" cellpadding="1" border="1">
<tr>
<td rowspan="3">COL 1 - ROW 1<br />COLSPAN 3</td>
<td>COL 2 - ROW 1</td>
<td>COL 3 - ROW 1</td>
</tr>
<tr>
<td rowspan="2">COL 2 - ROW 2 - COLSPAN 2<br />text line<br />text line</td>
<td>COL 3 - ROW 2</td>
</tr>
<tr>
<td>COL 3 - ROW 3</td>
</tr>
</table>
EOD;
Could you please check my html table code and help me to find the mistake.
After the first <tr>, you have an extra </tr>, making the document invalid. Indented, your HTML is:
<table cellspacing="0" cellpadding="1" border="1">
<tr>
<td>aaaaa</td>
<td colspan="2" rowspan="2">bbbb</td>
</tr>
<td rowspan="2">hhhhh</td>
</tr>
<tr>
<td>iiii</td>
<td>jjjj</td>
</tr>
</table>
i have a page contains a table and this table contains a lot of coding like this
<table class="table">
<tbody>
<tr >
<td width="20" class="tabletop">م</td>
<td class="tabletop" >name</td>
<td class="tabletop" style="width:120px">date</td>
<td class="tabletop" style="width:120px">note1</td>
<td class="tabletop" style="width:100px">note2</td>
<td class="tabletop" style="width:90px">note3</td>
</tr>
<? $res=mysql_query($sql);
while($resArr=mysql_fetch_array($res)){ ?>
<tr style="width:700px">
<td class="tabletext"><?= ++$serial;?></td>
<td class="tabletext" ><?= $resArr[stName];?></td>
<td class="tabletext"><?= $resArr['date'];?></td>
<td class="tabletext" ><?= $resArr[matName];?></td>
<td class="tabletext" ><? if($resArr[exam]==1) echo "work";else echo "final";?></td>
<td class="tabletext" ><? if($resArr[exam_type]==1) echo "prac";else echo "test";?></td>
</tr>
<? }?>
</tbody>
</table>
as you see the table has php coding
now i want to store the whole table in variable so i can send it to pdf printing library tcpdf
You can use heredoc syntax, but you need to move the conditionals outside:
<?php
if($resArr['exam']==1) $exam = "work"; else $exam = "final";
if($resArr["exam_type"]==1) $examtype = "prac";else $examtype = "test";
$var = <<<EOT
<table class="table">
<tbody>
<tr >
<td width="20" class="tabletop">م</td>
<td class="tabletop" >name</td>
<td class="tabletop" style="width:120px">date</td>
<td class="tabletop" style="width:120px">note1</td>
<td class="tabletop" style="width:100px">note2</td>
<td class="tabletop" style="width:90px">note3</td>
</tr>
$res=mysql_query($sql);
while($resArr=mysql_fetch_array($res)){
<tr style="width:700px">
<td class="tabletext">{++$serial}</td>
<td class="tabletext" >{$resArr["stName"]}</td>
<td class="tabletext">{$resArr["date"]}</td>
<td class="tabletext" >{$resArr["matName"]}</td>
<td class="tabletext" >{$exam}</td>
<td class="tabletext" >{$examtype}</td>
</tr>
<? }?>
</tbody>
</table>
EOT;
echo $var;
Another way, if you already have all of this code and want to save it:
Before the table:
<?php ob_start(); ?>
After the table:
<?php $output = ob_get_contents(); ?>
The table will still be displayed and you can use $output to send to the PDF.
The code im using as follows
ob_start();
?>
<table cellspacing="0" cellpadding="1" border="1">
<tr>
<td align="center" rowspan="3"><br /><? echo "لا اله الا الله"; ?></td>
<td align="center" class="exclude">COL 2 - ROW 1</td>
<td align="center">COL 3 - ROW 1</td>
</tr>
<tr>
<td align="center" rowspan="2">COL 2 - ROW 2 - COLSPAN 2<br />text line<br />text line<br />text line<br />text line</td>
<td align="center">COL 3 - ROW 2</td>
</tr>
<tr>
<td align="center">COL 3 - ROW 3</td>
</tr>
</table>
<?
$tbl=ob_get_clean();
i want to exclude or filter some cells from the above code before send it for another processing
You can then create a style which will hide those cells for you.
ob_start();
?>
<style>
.exclude{display:none}
</style>
<table cellspacing="0" cellpadding="1" border="1">
...
This is my email.php page coding. My php email function code working perfectly. I'm faced a small problem here. I didn't get the database records inside the while($t_row = mysql_fetch_array($tariff_query)){}. But, it send the remaining records from database correctly. How to send the database records of inside the while($t_row = mysql_fetch_array($tariff_query)){}?
include("config.php");
if(isset($_GET["id"]))
{
$id = mysql_real_escape_string($_GET["id"]);
$query = mysql_query("SELECT * FROM ebvouchers WHERE VoucherID = $id");
$row = mysql_fetch_object($query);
echo mysql_error();
$tariff_query = mysql_query("SELECT * FROM ebvouchertariffs WHERE VoucherID_Fk = $id");
$strMessage = "<table width=1200 align=center cellpadding=0 cellspacing=0 bgcolor=#FFFFFF>
<tr>
<td width=1026 height=8 colspan=2> </td>
</tr>
<tr>
<td colspan=8>
<table class=glow width=1070 border=0 align=center cellpadding=0 cellspacing=0>
<tr>
<td height=40 colspan=4 style=border-radius: 5px 5px 0px 0px; class=headdetail>GUEST DETAILS </td>
</tr>
<tr>
<td width=263 height=10 class=detailsfont> </td>
<td width=228> </td>
<td width=239 class=detailsfont> </td>
<td width=340> </td>
</tr>
<tr>
<td height=40 class=detailsfont>Voucher ID :</td>
<td width=228 class=fetchfont>$row->VoucherID</td>
<td width=239 class=detailsfont>Voucher Reference Number :</td>
<td width=340 class=fetchfont>$row->VoucherReference</td>
</tr>
//some codes
//some codes
//some codes
//some codes
//some codes
//some codes
//some codes
<tr>
<td colspan=4>
<table class=myborder width=1050 border=0 align=center cellpadding=10 cellspacing=0>
<tr>
<td width=70 height=40 class=tarifffont>Serial No</td>
<td width=130 class=tarifffont>Date</td>
<td width=250 class=tarifffont>Particulars</td>
<td width=100 class=tarifffont>No of Nights</td>
<td width=100 class=tarifffont>Rate</td>
<td width=100 class=tarifffont>Price</td>
<td width=100 class=tarifffont>Tax %</td>
</tr>";
while($t_row = mysql_fetch_array($tariff_query))
{
"<tr>
<td class=insidetariff>". $t_row['TariffSlNo'] ."</td>
<td class=insidetariff>". $t_row['TariffDate'] ."</td>
<td class=fetchfont>". $t_row['TariffParticulars'] ."</td>
<td class=insidetariff>". $t_row['NoOfNights'] ."</td>
<td class=insidetariff>". $t_row['TariffRate'] ."</td>
<td class=insidetariff>". $t_row['TariffPrice'] ."</td>
<td class=insidetariff>". $t_row['TariffTax'] ."</td>
</tr>";
}
"<tr>
<td height=40 colspan=2 class=detailsfont>Total Price (Overall Price) : </td>
<td height=20 colspan=2 class=tarifffont>$tt_row->TariffAddTotal</td>
<td height=20 class=insidetariff>Net Total (Overall Tax) : </td>
<td height=20 colspan=2 class=tarifffont>$tt_row->TariffNetTotal</td>
</tr>
<tr>
<td height=20 colspan=7 class=detailsfont> </td>
</tr>
<tr>
<td height=40 colspan=5 class=detailsfont>Final Amount : </td>
<td height=40 colspan=2 class=tarifffont>$tt_row->TariffFinalTotal</td>
</tr>
</table></td>
</tr>
<td colspan=4> </td>
</table>
</td>
</tr>";
}
You must append the data to the string. So the code will be like this:
while ($t_row = mysql_fetch_array($tariff_query)) {
$strMessage .= "<tr>
<td class=insidetariff>". $t_row['TariffSlNo'] ."</td>
<td class=insidetariff>". $t_row['TariffDate'] ."</td>
<td class=fetchfont>". $t_row['TariffParticulars'] ."</td>
<td class=insidetariff>". $t_row['NoOfNights'] ."</td>
<td class=insidetariff>". $t_row['TariffRate'] ."</td>
<td class=insidetariff>". $t_row['TariffPrice'] ."</td>
<td class=insidetariff>". $t_row['TariffTax'] ."</td>
</tr>";
}
$strMessage .= "<tr>
<td height=40 colspan=2 class=detailsfont>Total Price (Overall Price)....
Also, use of mysql_* functions is deprecated and will be removed in the future. You should use mysqli_* functions now.
You going wrong way.First assign while loop data to variable then add to mail message like this:
$tbl = '';
while($t_row = mysql_fetch_array($tariff_query))
{
$tbl .= "<tr>
<td class=insidetariff>". $t_row['TariffSlNo'] ."</td>
<td class=insidetariff>". $t_row['TariffDate'] ."</td>
<td class=fetchfont>". $t_row['TariffParticulars'] ."</td>
<td class=insidetariff>". $t_row['NoOfNights'] ."</td>
<td class=insidetariff>". $t_row['TariffRate'] ."</td>
<td class=insidetariff>". $t_row['TariffPrice'] ."</td>
<td class=insidetariff>". $t_row['TariffTax'] ."</td>
</tr>";
}
while now on you message add this variable like this :
$strMessage = "<table>.....".$tbl."....";
You are not concatenating the string for variable $strMessage.
In while loop you should concate string with your variable and at last echo it.
Store data calculated inside the while loop as :
while($t_row = mysql_fetch_array($tariff_query))
{
$strMessage .= "<tr>
<td class=insidetariff>". $t_row['TariffSlNo'] ."</td>
<td class=insidetariff>". $t_row['TariffDate'] ."</td>
<td class=fetchfont>". $t_row['TariffParticulars'] ."</td>
<td class=insidetariff>". $t_row['NoOfNights'] ."</td>
<td class=insidetariff>". $t_row['TariffRate'] ."</td>
<td class=insidetariff>". $t_row['TariffPrice'] ."</td>
<td class=insidetariff>". $t_row['TariffTax'] ."</td>
</tr>";
}
And also assign string after while loop to $strMessage :
$strMessage .= "<tr>
<td height=40 colspan=2 class=detailsfont>Total Price (Overall Price) : </td>
<td height=20 colspan=2 class=tarifffont>$tt_row->TariffAddTotal</td>
<td height=20 class=insidetariff>Net Total (Overall Tax) : </td>
<td height=20 colspan=2 class=tarifffont>$tt_row->TariffNetTotal</td>
</tr>
<tr>
<td height=20 colspan=7 class=detailsfont> </td>
</tr>
<tr>
<td height=40 colspan=5 class=detailsfont>Final Amount : </td>
<td height=40 colspan=2 class=tarifffont>$tt_row->TariffFinalTotal</td>
</tr>
</table></td>
</tr>
<td colspan=4> </td>
</table>
</td>
</tr>";
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>";
?>