replace string in the table - php

I have to check a string and replace if the attribute is equal to "Destaque:" in the case where the attribute matches it fails to print the line, but I'm confused with the functions, can someone help me?
<?php
class Produto_Atributo
{
function __construct()
{
}
function produtoAtributo($codigo)
{
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$banco_magento = Mage::getSingleton('core/resource')->getConnection('core_write');
$sql = "SELECT * FROM tw_produto_atributo where entity_id=" . $codigo;
$resultadoSql = $banco_magento->fetchAll($sql);
$count = 0;
foreach ($resultadoSql as $linha) {
$classe = '';
if ($count % 2 == 0) {
$classe = 'par';
}
else {
$classe = 'impar';
}
$_atributo = $this->recuperarAtributo($linha['attribute_id']);
$_optionText = $this->recuperarOptionid($_atributo, $linha['option_id']);
$descricao=$linha['ds_conteudo'] ;
$order = array("\n");
$replace = '<br />';
$newstr = str_replace($order, $replace, $descricao);
if (isset($linha['ds_conteudo']) && $linha['ds_conteudo'] != '') {
echo '<tr class="active '.$classe.'">
<td class="table-caracteristica-titulo" style="padding-left: 45px !important;padding-right: 45px !important; "> ' . ucwords( strtolower($_optionText)) . '</td>
<td class="table-caracteristica-descricao" style="padding-left: 45px !important;padding-right: 45px !important;"> ' . $newstr. '</td>
</tr>';
} else {
echo '<tr class="'.$classe.'">
<td class="table-caracteristica-titulo" style="padding-left: 45px !important;padding-right: 45px !important;">'if($_atributo->getFrontend_label()==!"Destaque:"){$_atributo->getFrontend_label();}else {'Loko'.$_atributo->getFrontend_label();} '</td>
<td class="table-caracteristica-descricao" style="padding-left: 45px !important;padding-right: 45px !important;"> ' . $_optionText . '</td>
</tr>';
}
$count = $count + 1;
}
}
function recuperarAtributo($atributo)
{
$cod = $atributo;
$attr = Mage::getModel('eav/entity_attribute')->getCollection()->addFieldToFilter('attribute_id', array('eq' => $cod))->getFirstItem();
return $attr;
}
function recuperarOptionid($atributo, $option_id)
{
return ($atributo->getSource()->getOptionText($option_id));
}
}

already got hahah
was very simple, here's the answer:
if (isset($linha['ds_conteudo']) && $linha['ds_conteudo'] != '') {
echo '<tr class="active '.$classe.'">
<td class="table-caracteristica-titulo" style="padding-left: 45px !important;padding-right: 45px !important; "> ' . ucwords( strtolower($_optionText)) . '</td>
<td class="table-caracteristica-descricao" style="padding-left: 45px !important;padding-right: 45px !important;"> ' . $newstr. '</td>
</tr>';
} else {
if($_atributo->getFrontend_label()<>"Destaque:"){
echo '<tr class="'.$classe.'">
<td class="table-caracteristica-titulo" style="padding-left: 45px !important;padding-right: 45px !important;">' . $_atributo->getFrontend_label() . '</td>
<td class="table-caracteristica-descricao" style="padding-left: 45px !important;padding-right: 45px !important;"> ' . $_optionText . '</td>
</tr>';
}
}

Related

mpdf columns width is not getting fixed and increases with data

I am creating a pdf of 9 columns using mpdf that shows a list of users In each row, 1 column is used for photograph. My problem is that I want the columns to be almost equal in width but in result, I am getting columns with different widths.
I have tried to set CSS of table as well as through mpdf option, but none of them worked.
My code is as under:
$a='<style>#page {
margin: 10pt;
}</style>';
$a .= '<table autosize="1" border="1" class="atable" style="font-family:Arial"><tr>
<th style="min-width: 60pt;max-width: 60pt; font-size:7pt">Sr.<br>No.</th>
<th style="min-width: 60pt;max-width: 60pt; font-size:7pt">Admission No.<br>Boarder/DayScholar<br>Admit Class<br>Admit Date<br>Exit Class<br>Exit Date</th>
<th style="min-width: 60pt;max-width: 60pt; font-size:7pt">Photograph</th>
<th style="min-width: 60pt;max-width: 60pt; font-size:7pt">Student Details<br>[Student Name<br>Father Name<br>Father Occupation<br>Mother Name<br>Mother Occupation]</th>
<th style="min-width: 60pt;max-width: 60pt; font-size:7pt">Date of Birth<br>Current Class<br>Current City<br>Board Roll No.<br>Percentage</th>
<th style="min-width: 60pt;max-width: 70pt; font-size:7pt">Old Details<br>[Address<br>Father Email<br>Father Mobile]</th>
<th style="min-width: 60pt;max-width: 75pt; font-size:7pt">Present Profile<br>(Alumi,<br>Ex-Student,<br>Current Student)</th>
<th style="min-width: 60pt;max-width: 65pt; font-size:7pt">Contact Details<br>[Email Id<br>Mobile<br>Father Mobile<br>Facebook Id<br>Twitter Id<br>Linked In Id]</th>
<th style="min-width: 60pt;max-width: 65pt; font-size:7pt">Remarks</th>
</tr><tr>'
//Here goes the data fetching php code followed by the below code
<td style="font-size: 10pt !important; text-align:center;">' . ++$i . '</td>
<td style="font-size:10pt !important; text-align:center;">' . $row['adm_no'] .'<br><font color="green">' . $row['d_b'] . '</font><br>' . $row['adm_class'] . '<br><font color="green">' . $fadmdate . '</font><br>' . $row['exit_class'] . '<br><font color="green">' . $fexit . '</font></td>
<td style="font-size:10pt !important; text-align:center;">'. '<div id="testimage"><img src="' . $gdImage . '" width="60pt" /></div></td><td style="font-size:10pt !important; text-align:center;">'. $row['stu_name'] .
'<br><font color="green">' . $row['fat_name'] . '</font><br>' . $row['fat_occ'] . '<br><font color="green">' . $row['mot_name'] . '</font><br>' . $row['mot_occ'] . '</td>
<td style="font-size:10pt !important; text-align:center;">'.
$fdob . '<br><font color="green">' . $row['stu_class'] . '</font><br>' . $row['cur_city'] . '<br><font color="green">' .$row['board_roll'] . '</font><br>' . $row['perc'] . '</td>
<td style="font-size:10pt !important; text-align:center;">'.
$row['addr']. '<br><font color="green">' . $row['fat_email'] . '</font><br>' . $row['fat_mob'] . '</td>
<td style="font-size:10pt !important; text-align:center;">'.
$cprofile .'</td>
<td style="font-size:10pt !important; text-align:center;">' . $row['email_id'] .'<br><font color="green">' . $row['phone_no'] . '</font><br>' . $row['fb_id'] . '<br><font class="green">' . $row['twitter_id'] . '</font><br>' . $row['linkedin_id'] . '</td><td style="font-size:10pt !important; text-align:left;">SMS:<br><font color="green">Email:</font><br>FB:</td>
</tr></table>
<?php
include("\mpdf\mpdf.php");
$mpdf=new mPDF('','A4');
$keep_table_proportions = TRUE;
$mpdf->shrink_tables_to_fit=1;
$mpdf->setFooter('Details ::: ' . date("d/m/Y") . ' ::: {PAGENO} / {nb}');
$mpdf->WriteHTML($a);
$mpdf->Output('mytable.pdf', 'D');
exit;
Even after setting max width to 70pt, The Old details column takes around 25% of the page width due to which other columns are squeezed badly and look goes weird and also the footer is no more visible.
try the following :
<table cellpadding="5px" autosize="1" border="1" width="100%" style="overflow: wrap">
Then add appropriate widths to your th and td long with appropriate font size, say 8 to 10 pt.
Then, at the end, modify your code as follows:
include("\mpdf\mpdf.php");
$mpdf=new mPDF('','A4');
$mpdf->simpleTables = true;
$mpdf->packTableData = true;
$mpdf->keep_table_proportions = TRUE;
$mpdf->shrink_tables_to_fit=1;
$mpdf->setFooter('Birthday Details ::: ' . date("d/m/Y") . ' ::: {PAGENO} / {nb}');
$mpdf->WriteHTML($a);
$mpdf->Output('mytable.pdf', 'D');
exit;
This will lso improve the performance. Dont forget to upvote if this helps.

Create a Table With Merged TH Cells

I am creating an Excel download code, in which I am merging the TH cells and looping through TR to put data under specific merged TH.
But all of data is reflecting on first TH row. Below is code:
$K=0;
while($ROW = $RESULT->fetch_assoc() )
{
if($ROW['type'] == $_GET['separate_id'])
{
$DATE[] = $ROW['end_time'];
$meta_values[] = $ROW['meta_values'];
$body = '
<table style="border:1px solid #000; border-collapse:collapse;">
<thead style="border:1px solid #000; padding:8px;width:150px; height:25px;font-size:15px">
';
foreach($DATE as $DATES)
{
$DATESVIEW = explode('T',$DATES);
$body .=' <th colspan="2">'.$DATESVIEW[0].'</th> ';
}
$body .= '
</thead>
';
foreach($meta_values as $VALS)
{
$META_VALS = explode(' | ',$VALS);
foreach($META_VALS as $VALUEs)
{
$REs = explode(' - ', $VALUEs);
$body .= '
<tbody>
<tr style="border:1px solid #000; padding:8px;width:150px; height:25px;font- size:15px">
<td style="border:1px solid #000; padding:8px; width:150px; height:25px;font-size:15px">'.$REs[0].'</td>
<td style="border:1px solid #000; padding:8px; width:150px; height:25px;font-size:15px">'.$REs[1].'</td>
</tr>
</tbody>
';
}
}
}
$K++;
}
$body .= '
</table>
';

Fetch more data inside foreach

So I need to fetch data such as section, item names and subtotal of every section from my database and get the grand total of all the items.
I stumble upon the code below and modify it to my requirements.
The code works perfectly but I need to display more data like Item description, Qty, Price, status and so on.
The code below works and have no problem whatsoever but i need more data (description, qty, price and so on) to display in my table but I can't figure out how to do it.
The data I need to display is also in the same row where projectscostbreakdown_areaname, projectscostbreakdown_itemname and projectscostbreakdown_totalcost are.
<?php
$projectsid = $_GET['projectrfpid'];
$itemdeleted = 1;
$itemfirstothers = 'OTHERS';
$query = $conn->prepare('SELECT projectscostbreakdown_id,
projectscostbreakdown_projectid,
projectscostbreakdown_areaname,
projectscostbreakdown_itemname,
projectscostbreakdown_itemdescription,
projectscostbreakdown_qty,
projectscostbreakdown_costpiece,
projectscostbreakdown_budgeted,
projectscostbreakdown_totalcost,
projectscostbreakdown_note,
projectscostbreakdown_addedby,
projectscostbreakdown_addeddate,
projectscostbreakdown_deleted,
projectscostbreakdown_lastedit,
projectscostbreakdown_lasteditby
FROM projectscostbreakdown WHERE projectscostbreakdown_projectid=:projectsid && projectscostbreakdown_deleted=:itemdeleted ORDER BY projectscostbreakdown_areaname=:itemfirstothers, projectscostbreakdown_areaname ASC, projectscostbreakdown_id DESC');
$query->bindParam(':projectsid', $projectsid, PDO::PARAM_INT);
$query->bindParam(':itemdeleted', $itemdeleted, PDO::PARAM_INT);
$query->bindParam(':itemfirstothers', $itemfirstothers, PDO::PARAM_INT);
$query->execute();
$data = array();
$data2 = array();
$numbering = 0; //for item count
$count = 1; //counter use for background color
while ( $row2 = $query->fetch() ) {
if ( empty($data[ $row2['projectscostbreakdown_areaname'] ]) ) {
$data[ $row2['projectscostbreakdown_areaname'] ]= array();
$data2[ $row2['projectscostbreakdown_itemdescription'] ][ $row2['projectscostbreakdown_qty'] ]= array();
}
if ( empty( $data[ $row2['projectscostbreakdown_areaname'] ][ $row2['projectscostbreakdown_itemname'] ] ) ) {
$data[ $row2['projectscostbreakdown_areaname'] ][ $row2['projectscostbreakdown_itemname'] ] = array();
$data2[ $row2['projectscostbreakdown_itemdescription'] ][ $row2['projectscostbreakdown_qty'] ]= array();
}
$data[ $row2['projectscostbreakdown_areaname'] ][ $row2['projectscostbreakdown_itemname'] ][] = $row2['projectscostbreakdown_totalcost'];
$data2[ $row2['projectscostbreakdown_itemdescription'] ][ $row2['projectscostbreakdown_qty'] ]= array();
}
print '<table width="100%" border="0"><tbody>';
$totalSum = 0;
foreach ( $data as $area => $item ) {
print '<tr style="background-color: white;"><td colspan="7" style="text-align: left;"><br /><br /><b><u>'. $area .'</u></b></td></tr>';
print '<tr style="background-color: #AAAAAA; text-align: center;">
<td width="20%""><b>Item name</b></td>
<td width="30%"><b>Description</b></td>
<td width="5%"><b>Qty.</b></td>
<td width="10%"><b>Cost/Piece</b></td>
<td width="10%"><b>Subtotal</b></td>
<td width="10%"><b>Budget</b></td>
<td width="15%"><b>Note /<br / >Entered by</b></td>
</tr>';
$totalArea = 0;
foreach ( $item as $item => $totalcost ) {
//while ( $data = $query->fetch() ) {
$numbering++;
$count++;
$class = ($count%2 == 0)? 'white': '#CCCCCC';
$sum = array_sum( $totalcost );
print '<tr style="background-color: '.$class.'">';
print '<td style="vertical-align: top; text-align: left;">'. $numbering .'. '. $item . '</td>';
print '<td style="vertical-align: top; text-align: left;">';
print_r($data2);
print '</td>';
print '<td style="vertical-align: top; text-align: right;"></td>';
print '<td style="vertical-align: top; text-align: right;"></td>';
print '<td style="vertical-align: top; text-align: right;">'. number_format($sum, 2,'.', ',') . '</td>';
print '<td style="vertical-align: top; text-align: right;"></td>';
print '<td style="vertical-align: top; text-align: left;"></td>';
print '</tr>';
$totalArea += $sum;
}
print '<tr style="background-color: lightgray; text-align: right;" ><td colspan="6">Section Total: </td><td>'. number_format($totalArea, 2,'.', ',') . '</td></tr>';
$totalSum += $totalArea;
}
print '<tr style="background-color: lightblue; text-align: right;" ><td colspan="6"><b>Grand Total: </b></td><td><b>'. number_format($totalSum, 2,'.', ',') . '</b></td></tr>';
echo '</tbody>
</table>';
?>
UPDATE
The output looks like this right now.
I need to include Description and Qty in the output but cant figure how to be done.
Section1
Item Name-----Description-----Qty-----Subtotal
item 1---------------------------------------------1000
item 2---------------------------------------------2000
----------------------------------Section Total: 3000
Section2
Item Name-----Description-----Qty-----Subtotal
item 3---------------------------------------------1000
----------------------------------Section Total: 1000
------------------------------------Grand Total: 4000
Complete code (more structured, fixed bugs):
<?php
$projectsid = $_GET['projectrfpid'];
$itemdeleted = 1;
$itemfirstothers = 'OTHERS';
$query = $conn->prepare('SELECT projectscostbreakdown_id,
projectscostbreakdown_projectid,
projectscostbreakdown_areaname,
projectscostbreakdown_itemname,
projectscostbreakdown_itemdescription,
projectscostbreakdown_qty,
projectscostbreakdown_costpiece,
projectscostbreakdown_budgeted,
projectscostbreakdown_totalcost,
projectscostbreakdown_note,
projectscostbreakdown_addedby,
projectscostbreakdown_addeddate,
projectscostbreakdown_deleted,
projectscostbreakdown_lastedit,
projectscostbreakdown_lasteditby
FROM projectscostbreakdown WHERE projectscostbreakdown_projectid=:projectsid && projectscostbreakdown_deleted=:itemdeleted ORDER BY projectscostbreakdown_areaname=:itemfirstothers, projectscostbreakdown_areaname ASC, projectscostbreakdown_id DESC');
$query->bindParam(':projectsid', $projectsid, PDO::PARAM_INT);
$query->bindParam(':itemdeleted', $itemdeleted, PDO::PARAM_INT);
$query->bindParam(':itemfirstothers', $itemfirstothers, PDO::PARAM_INT);
$query->execute();
$data = array();
$data2 = array();
$numbering = 0; //for item count
$count = 1; //counter use for background color
$itemData = $query->fetchAll();
$query->execute();
while ($row2 = $query->fetch()) {
if (empty($data[$row2['projectscostbreakdown_areaname']]) ) {
$data[$row2['projectscostbreakdown_areaname']]= array();
$data2[$row2['projectscostbreakdown_itemdescription']][$row2['projectscostbreakdown_qty']] = array();
}
if (empty($data[$row2['projectscostbreakdown_areaname']][$row2['projectscostbreakdown_itemname']])) {
$data[$row2['projectscostbreakdown_areaname']][ $row2['projectscostbreakdown_itemname']] = array();
$data2[$row2['projectscostbreakdown_itemdescription']][$row2['projectscostbreakdown_qty']]= array();
}
$data[$row2['projectscostbreakdown_areaname']][$row2['projectscostbreakdown_itemname']][] = $row2['projectscostbreakdown_totalcost'];
$data2[$row2['projectscostbreakdown_itemdescription']][$row2['projectscostbreakdown_qty']] = array();
}
print '<table width="100%" border="0"><tbody>';
$totalSum = 0;
foreach ( $data as $area => $item ) {
print '<tr style="background-color: white;"><td colspan="7" style="text-align: left;"><br /><br /><b><u>'. $area .'</u></b></td></tr>';
print '<tr style="background-color: #AAAAAA; text-align: center;">
<td width="20%""><b>Item name</b></td>
<td width="30%"><b>Description</b></td>
<td width="5%"><b>Qty.</b></td>
<td width="10%"><b>Cost/Piece</b></td>
<td width="10%"><b>Subtotal</b></td>
<td width="10%"><b>Budget</b></td>
<td width="15%"><b>Note /<br / >Entered by</b></td>
</tr>';
$totalArea = 0;
foreach ( $item as $item => $totalcost ) {
$count++;
echo $numbering.' ';
$class = ($count % 2 == 0) ? 'white' : '#CCCCCC';
$sum = array_sum($totalcost);
print '<tr style="background-color: '.$class.'">';
print '<td style="vertical-align: top; text-align: left;">'. $numbering .'. '. $item . '</td>';
print '<td style="vertical-align: top; text-align: left;">'.$itemData[$numbering]['projectscostbreakdown_itemdescription'].'</td>';
print '<td style="vertical-align: top; text-align: right;"></td>';
print '<td style="vertical-align: top; text-align: right;"></td>';
print '<td style="vertical-align: top; text-align: right;">'. number_format($sum, 2,'.', ',') . '</td>';
print '<td style="vertical-align: top; text-align: right;"></td>';
print '<td style="vertical-align: top; text-align: left;"></td>';
print '</tr>';
$numbering++;
$totalArea += $sum;
}
print '<tr style="background-color: lightgray; text-align: right;" ><td colspan="6">Section Total: </td><td>'. number_format($totalArea, 2,'.', ',') . '</td></tr>';
$totalSum += $totalArea;
}
print '<tr style="background-color: lightblue; text-align: right;" ><td colspan="6"><b>Grand Total: </b></td><td><b>'. number_format($totalSum, 2,'.', ',') . '</b></td></tr>';
echo '</tbody></table>';
?>
Basically, what I did (which might not be the best option but I couldn't think anything better) was I used $itemData = $query->fetchAll(); after executing $query->execute();. Now if we leave everything the same, table will be empty since pointer is at the last element. Therefore, we must execute again the same query by writing an additional $query->execute(); right after $itemData = $query->fetchAll();.
Now we have basically the same thing as in your example but with one additional variable $itemData with all information about items. To bring out description, quantity, etc. now we can use $itemData[$numbering]['projectscostbreakdown_itemdescription'] where $numbering stands for array's index number.

Next and Previous Buttons with php

I have been having a problem getting next and previous buttons to work using a php webpage connected to mysql database. I am not sure what is wrong but i think it may have something to do with the offset. Right now the button are not working at all you click them and nothing happens. Also the form is made as a search page.
Here is the search code:
<?php
include("../web-admin/dbconfiginc.php");
$result = mysql_query("SELECT * FROM videos WHERE ID = '$ID'");
$row = mysql_fetch_array($result);
?><strong></strong>
<title>Search </title>
</head>
<body>
<table align="center" width="1024" border="0">
<tr>
<td valign="top" align="center" width="70%" style="padding-top:10px;" class="lhc">
<div align="center" style="margin-top: 50px; padding-bottom: 50px;">
<?php
$Keyword = $_POST['Keyword'];
$GuestName = $_POST['GuestName'];
$Day = $_POST['Day'];
$Month = $_POST['Month'];
$Year = $_POST['Year'];
if(isset($cancel))
{
header("Location:index.php");
exit;
}
$qry_string = "SELECT * FROM videos ";
$search = "";
if(!empty($Keyword))
{
$End_String = "(Blurb LIKE '%$Keyword%' OR Title LIKE '%$Keyword%')";
$search .="&Keyword=$Keyword";
}
if(!empty($GuestName))
{
if(isset($End_String))
{
$End_String .= " AND (GuestName LIKE '%$GuestName%')";
}
else
{
$End_String = "(GuestName LIKE '%$GuestName%')";
}
$search .="&GuestName=$GuestName";
}
if(!empty($Day))
{
if(isset($End_String))
{
$End_String .= " AND (DAYOFMONTH(Publish_Date) = '$Day')";
}
else
{
$End_String = "(DAYOFMONTH(Publish_Date) = '$Day')";
}
$search .="&Day=$Day";
}
if(!empty($Month))
{
if(isset($End_String))
{
$End_String .= " AND (MONTH(Publish_Date) = '$Month')";
}
else
{
$End_String = "(MONTH(Publish_Date) = '$Month')";
}
$search .="&Month=$Month";
}
if(!empty($Year))
{
if(isset($End_String))
{
$End_String .= " AND (YEAR(Publish_Date) = '$Year')";
}
else
{
$End_String = "(YEAR(Publish_Date) = '$Year')";
}
$search .="&Year=$Year";
}
if(!empty($Active))
{
if(isset($End_String))
{
$End_String .= " AND (GuestName LIKE '%$GuestName%')";
}
else
{
$End_String = "(GuestName LIKE '%$GuestName%')";
}
$search .="&GuestName=$GuestName";
}
if (!isset($offset)) $offset=0;
if(isset($End_String))
{
$qry_string = $qry_string." WHERE ".$End_String . "ORDER BY Publish_Date DESC LIMIT $offset, 101";
}
else
{
$qry_string = $qry_string."ORDER BY Publish_Date DESC LIMIT $offset, 101";
}
$result = mysql_query($qry_string);
echo mysql_error();
?>
And here is the code that displays the results from the database
<?php
$num_records = mysql_num_rows($result);
if (!isset($search))
$search = "";
?>
<table width="100%" style="border-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="0"><tr><td>
</td></tr></table>
<table width="95%" align="center" style="border-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="0">
<tr>
<td width=25%>
<?php
if ($offset > 99) {
echo '<a href='.$_SERVER['PHP_SELF'].'?$offset='.($offset-100).'>Previous 100</a>';
} else {
echo 'Previous 100';
}
?>
</td>
<td align=center width=10%>
<span class="content1"><a href=search.php>Search </a></span>
</td>
<td align=right width=25%>
<?php
if($num_records == 101) {
echo 'Next 100';
} else {
echo 'Next 100';
}
?>
</td>
</tr>
</table>
<table align="center" border="0" cellpadding="3" cellspacing="1" bgcolor="#666666" style="margin: 5px 15px; 5px 10px;">
<tr style="background: #9ae6f1; font-family: Verdana; font-weight: bold; font-size: 18px;">
<td style="width: 65%; padding: 5px;">
Video
</td>
<td align="center" style="width: 10%; padding: 5px;">
Guest Name
</td>
<td align="center" style="width: 10%; padding: 5px;">
Date
</td>
</tr>
<?php
$count = 1;
$bgc = 1;
while($row = mysql_fetch_array($result))
{
if ($count > 100) break;
echo '<tr style="background: ';
if (($bgc == 0 ? $bgc=1 : $bgc=0) == 0) echo "#FFFFFF";
else echo "#E6E6E6";
echo ';">';
echo '<td><div style="padding: 3px;" class="content"><a href=../../watch/watch.php?ID='.$row[ID].'>'.$row[Title].'</a></div></td>';
echo '<td><div style="padding: 3px;" class="content">'.$row[GuestName].'</div></td>';
echo '<td><div align="center" style="padding: 3px;" class="content">'.$row[Publish_Date].'</div></td></tr>';
$count++;
}
?>
</table>
<table width="95%" align="center" style="border-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="0">
<tr>
<td width=25%>
<?php
if($offset > 99) {
echo '<span class="content"><a href='.$_SERVER['PHP_SELF'].'?offset='.($offset-100).$search.'>Previous 100</a></span>';
} else {
echo 'Previous 100';
}
?>
</td>
<td align=center width=10%>
<span class="content1"><a href=search.php>Search </a></span>
</td>
<td align=right width=25%>
<?php
if($num_records == 101) {
echo '<span class="content"><a href='.$_SERVER['PHP_SELF'].'?offset='.($offset+100).$search.'>Next 100</a></span>';
} else {
echo 'Next 100';
}
?>
</td>
</tr>
</table>
Would really appreciate some help trying to figure this out or some points in the right direction. Thank you!

I keep getting "TCPDF ERROR: Wrong page number on setPage() function:"

I want to print a class bill and i keep getting:
TCPDF ERROR: Wrong page number on setPage() function
Below is my code:
<?php
ob_start();
require_once '../includes/header.php';
require_once '../tcpdf/tcpdf.php';
require_once '../classes/InstitutionDetail.php';
require_once '../classes/ClassMembership.php';
require_once '../classes/Pupil.php';
require_once '../classes/Admission.php';
require_once '../classes/User.php';
require_once '../classes/Photo.php';
require_once '../classes/Bill.php';
require_once '../classes/Payments.php';
confirm_logged_in();
$institutionDetail = new InstitutionDetail();
$classMembership = new ClassMembership();
$pupil = new Pupil();
$admission = new Admission();
$user = new User();
$photo = new Photo();
$bill = new Bill();
$payment = new Payments();
$getUserDetails = $user->getUserByUsername($_SESSION["username"]);
$splitAccessPages = explode("//", $getUserDetails["access_pages"]);
for ($i = 0; $i < count($splitAccessPages); $i++) {
if (!in_array("print_class_bills", $splitAccessPages, TRUE)) {
redirect_to("logout_access.php");
}
}
//$getAcademicTerm = $academicTerm->getActivatedTerm();
//$get_academic_term = $getAcademicTerm["academic_year"] . "/" . $getAcademicTerm["term"];
if (!isset($_SESSION["chosen_term"], $_SESSION["selected_class_name"])) {
// redirect_to("student_bill.php");
$_SESSION["chosen_term"] = "";
$_SESSION["selected_class_name"] = "";
}
$getInstitutionDetail = $institutionDetail->getInstitutionDetails();
$getSchool_name = $getInstitutionDetail["school_name"];
$getSchoolMotor = $getInstitutionDetail["school_motor"];
$getPostalAddress = $getInstitutionDetail["postal_address"];
$getTelephoneNumbers = $getInstitutionDetail["telephone_1"] . " " . $getInstitutionDetail["telephone_2"] . " " . $getInstitutionDetail["telephone_3"];
class MYPDF extends TCPDF {
//Page header
public function Header() {
}
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-90);
// Set font
$this->SetFont('helvetica', '', 8);
// Page number
// date_default_timezone_set("Africa/Accra");
// $this->Cell(0, 10, date("d/m/Y h:i:sa") . " " . 'Page ' . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');
$takeNote = "<strong><u>FOOTNOTES:</u></strong>";
$divSaparatefoot = '<div style="width:auto; background-color:mintcream; height:25px; border-bottom:3px solid #ddd;padding-bottom:3px;">'.'</div>';
// $horizontalLine = "<hr style=background:burlywood; height: 5px; />";
$space = "<p></p>";
$msg = "1. When <strong>Total Fees</strong> indicate <strong>credit</strong>, it means that, the school owes the student the said amount.";
$info = "2. All fees must be paid on or before the <strong>re-opening date</strong>.";
$bankNote = "<strong>Bankers:</strong>";
$company = "<strong><em>Software by ANIDROL GHANA:+233 26-764-2898 /+233 24-774-5156</em></strong>";
$institutionDetail = new InstitutionDetail();
$getInstitutionDetail = $institutionDetail->getInstitutionDetails();
$getBank_1 = "1. <strong>" . $getInstitutionDetail["bank_1"] . "</strong> Branch: <strong>" . $getInstitutionDetail["bank_1_branch"] . "</strong> Account Number: <strong>" . $getInstitutionDetail["bank_1_account_number"] . "<strong>";
$getBank_2 = "2. <strong>" . $getInstitutionDetail["bank_2"] . "</strong> Branch: <strong>" . $getInstitutionDetail["bank_2_branch"] . "</strong> Account Number: <strong>" . $getInstitutionDetail["bank_2_account_number"] . "<strong>";
$getBank_3 = "3. <strong>" . $getInstitutionDetail["bank_3"] . "</strong> Branch: <strong>" . $getInstitutionDetail["bank_3_branch"] . "</strong> Account Number: <strong>" . $getInstitutionDetail["bank_3_account_number"] . "<strong>";
$this->writeHTML($divSaparatefoot, true, 0, true, 0);
$this->writeHTML($takeNote, true, 0, true, 0);
$this->writeHTML($space, true, 0, true, 0);
$this->writeHTML($msg, true, 0, true, 0);
$this->writeHTML($info, true, 0, true, 0);
$this->writeHTML($space, true, 0, true, 0);
$this->writeHTML($bankNote, true, 0, true, 0);
$this->writeHTML($getBank_1, true, 0, true, 0);
$this->writeHTML($getBank_2, true, 0, true, 0);
$this->writeHTML($getBank_3, true, 0, true, 0);
$this->writeHTML($company, true, 0, true, 0, 'R');
}
}
$pdf = new MYPDF("", PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set some language-dependent strings (optional)
if (#file_exists(dirname(__FILE__) . "/lang/eng.php")) {
require_once(dirname(__FILE__) . "/lang/eng.php");
$pdf->setLanguageArray($l);
}
// set font
$pdf->SetFont('times', '', 11);
$getClassStudentById = $classMembership->getClassStudentsById($_SESSION["chosen_term"], $_SESSION["selected_class_name"]);
foreach ($getClassStudentById as $value) {
$pdf->startPageGroup();
$pdf->AddPage();
$pdf->setJPEGQuality(75);
$getSingleBillAmount = $bill->getSingleBillingAmount($value["pupil_id"]);
$singleBillAmount = $getSingleBillAmount["billAmount"];
$getTermFees = $bill->getTermFees($value["pupil_id"], $_SESSION["chosen_term"]);
$getPTAAll = $bill->getPTAFeesAll($value["pupil_id"]);
// $termFeesOnly = number_format($getTermFees["termFees"], 2, ".", ",");
$getPTA = $bill->getPTAFees($value["pupil_id"], $_SESSION["chosen_term"]);
$termFees = number_format(($getTermFees["termFees"] + $getPTA["ptaFees"]), 2, ".", ",");
if ($termFees <= 0) {
if ($termFees == 0) {
$termFeesFormated = "";
} else {
$termFeesFormated = "GH¢" . str_replace("-", "", $termFees) . " Credit";
}
} else {
$termFeesFormated = "GH¢" . $termFees;
}
$getFeesPayable = $bill->getStudentAccount($value["pupil_id"]);
$getTotalFeesPaid = $bill->getTotalFeesPaid($value["pupil_id"]);
$getPTAFeesPaid = $bill->getPTAFeesPaid($value["pupil_id"]);
// $getBalance = number_format((($getFeesPayable["allFeesPayable"] + $singleBillAmount + $getPTAAll["ptaFeesAll"]) - ($getTotalFeesPaid["allFeesPaid"])), 2, ".", ",");
$getBalance = number_format((($getFeesPayable["allFeesPayable"] + $singleBillAmount + $getPTAAll["ptaFeesAll"]) - ($getTotalFeesPaid["allFeesPaid"] + $getPTAFeesPaid["ptaFeesPaid"] + $termFees)), 2, ".", ",");
if ($getBalance <= 0) {
if ($getBalance == 0) {
$balanceBroughtForward = "-";
} else {
$balanceBroughtForward = "GH¢" . str_replace("-", "", $getBalance) . " Credit";
}
} else {
$balanceBroughtForward = "GH¢" . $getBalance . " Debit";
}
// $totalFees = number_format(((($getFeesPayable["allFeesPayable"] - $getTotalFeesPaid["allFeesPaid"]) + $singleBillAmount) + $termFees), 2, ".", ",");
$totalFees = number_format((($getFeesPayable["allFeesPayable"] + $singleBillAmount + $getPTAAll["ptaFeesAll"] + $termFees) - ($getTotalFeesPaid["allFeesPaid"] + $getPTAFeesPaid["ptaFeesPaid"] + $termFees)), 2, ".", ",");
if ($totalFees <= 0) {
if ($totalFees == 0) {
$balanceCarriedForward = "-";
} else {
$balanceCarriedForward = "GH¢" . str_replace("-", "", $totalFees) . " Credit";
}
} else {
$balanceCarriedForward = "GH¢" . $totalFees;
}
// table
$getStudentPhoto = $photo->getPhotoById($value["pupil_id"]);
$studentPhoto = "../" . $getStudentPhoto["photo_url"];
$getLogoID = $photo->getSchoolLogoID();
$getSchoolLogo = $photo->getSchoolLogo($getLogoID["logo_id"]);
$schoolLogo = "../" . $getSchoolLogo["photo_url"];
$heading = "<span>GHANA EDUCATION SERVICE</span>"
. "<h1>" . $getSchool_name . "</h1>"
. "<span>" . $getPostalAddress . "</span><br />"
. "<span>" . $getTelephoneNumbers . "</span>";
$pdf->Image($studentPhoto, 155, 60, 35, 35, '', '', '', true, 150, '', false, false, 0, false, false, false);
$pdf->Image($schoolLogo, 5, 7, 34, 37, '', '', '', true, 150, '', false, false, 0, false, false, false);
$tbl_head_heading = '<table cellspacing = "0" cellpadding = "5">';
$tbl_foot_heading = '</table>';
$tbl_heading = '';
$tbl_heading .= '
<tbody>
<tr>
<td style="text-align: center; background-color: #666; color: #fff;" colspan="4">' . $heading . '</td>
</tr>
</tbody>';
$pdf->writeHTML($tbl_head_heading . $tbl_heading . $tbl_foot_heading, true, false, true, false, '');
$className ='<div style="width:auto; background-color:grey;">'.'<b>'. '<strong style="color:#fff; font-size:12px">'. htmlentities(strtoupper($_SESSION["chosen_term"] . " " . "Term Student Bill")) . '</strong>'.'</b>'.'</div>';
$pdf->writeHTML($className, true, 0, true, 0, 'C');
// $horizontalLineII = '<hr style="">'.'</hr>';
$divSaparate = '<div style="width:auto; background-color:mintcream; height:25px; border-bottom:3px solid #ddd;padding-bottom:3px;">'.'</div>';
$pdf->writeHTML($divSaparate);
//$pdf->writeHTML($horizontalLineII);
$headingSpace = "<div></div>";
$pdf->writeHTML($headingSpace, true, 0, true, 0);
//$horizontalLine = "<hr style='background-color:burlywood; height: 5px;'>"."</hr>";
$divSaparateLine = '<div style="width:auto; background-color:mintcream; height:25px; border-bottom:3px solid #ddd;padding-bottom:3px;">'.'</div>';
$getStudentData = $pupil->getPupilById($value["pupil_id"]);
$getStudentName = $getStudentData["other_names"] . " " . $getStudentData["family_name"];
$getStudentID = $getStudentData["pupil_id"];
$getGender = $getStudentData["sex"];
$getBoardingStatus = $value["boarding_status"];
$getClassName = $value["class_name"];
$tbl_head_title = '<table cellspacing = "10" cellpadding = "0" border = "0">';
$tbl_foot_title = '</table>';
$tbl_title = '';
$tbl_title .= '
<tbody>
<tr style="color: #000;">
<td style="text-align: right; width: 20%;"><strong>Name:</strong></td>
<td style="text-align: left; font-weight:bold;margin:5px; border-bottom:1.5px solid #ddd;padding-bottom:3px;">' . $getStudentName . '</td>
</tr>
<tr style="color: #000;">
<td style="text-align: right; width: 20%;"><strong>ID Number:</strong></td>
<td style="text-align: left; border-bottom:1.5px solid #ddd;padding-bottom:3px; width:100px;">' . $getStudentID . '</td>
</tr>
<tr style="color: #000;">
<td style="text-align: right; width: 20%; "><strong>Gender:</strong></td>
<td style="text-align: left; border-bottom:1.5px solid #ddd;padding-bottom:3px; width:100px;">' . $getGender . '</td>
</tr>
<tr style="color: #000;">
<td style="text-align: right; width: 20%;"><strong>Status:</strong></td>
<td style="text-align: left; border-bottom:1.5px solid #ddd;padding-bottom:3px; width:100px;">' . $getBoardingStatus . '</td>
</tr>
<tr style="color: #000;">
<td style="text-align: right; width: 20%;"><strong>Class:</strong></td>
<td style="text-align: left; font-weight:bold; border-bottom:1.5px solid #ddd;padding-bottom:3px; width:100px;">' . $getClassName . '</td>
</tr>
<tr style="color: #000;">
<td style="text-align: right; width: 20%;"><strong>Balance b/f:</strong></td>
<td style="text-align: left;">' . $balanceBroughtForward . '</td>
</tr>
<tr style="color: #000;">
<td style="text-align: right; width: 20%;"><strong>Term Fees:</strong></td>
<td style="text-align: left;">' . $termFeesFormated . '</td>
</tr>
<tr style="color: #000;">
<td style="text-align: right; width: 20%;"><strong>Total Fees:</strong></td>
<td style="text-align: left;">' . $balanceCarriedForward . '</td>
</tr>
</tbody>';
$pdf->writeHTML($tbl_head_title . $tbl_title . $tbl_foot_title, FALSE, false, true, false, '');
$pdf->writeHTML($divSaparateLine, true, 0, true, 0);
// list of bill items
$tbl_head_description = '<table cellspacing = "2" cellpadding = "5" border = "0">';
$tbl_foot_description = '</table>';
$tbl_description = '';
$tbl_description .= '
<tbody>
<tr style="color: #000;">
<td style="width: 8.5%;"> </td>
<td style="width: 67%; text-align: left;">' . "<strong>BILL ITEMS</strong>" . '</td>
<td style="text-align: right; width: 16%;">' . "<strong>GH¢</strong>" . '</td>
</tr>
</tbody>';
$pdf->writeHTML($tbl_head_description . $tbl_description . $tbl_foot_description, FALSE, false, true, false, '');
$classBillItemsForStudent = $bill->getClassBillForStudent($value["class_name"], $_SESSION["chosen_term"]);
foreach ($classBillItemsForStudent as $classBillItemStudent) {
if ($getBoardingStatus === "Day Student") {
$schoolFees = $classBillItemStudent["day_amount"];
} else {
$schoolFees = $classBillItemStudent["boarding_amount"];
}
$tbl_head_item = '<table cellspacing = "1" cellpadding = "0" border = "0">';
$tbl_foot_item = '</table>';
$tbl_item = '';
$tbl_item .= '
<tbody>
<tr style="color: #000;">
<td style="width: 10%;"> </td>
<td style="width: 70%;">' . $classBillItemStudent["bill_item"] . '</td>
<td style="text-align: right; width: 10%;">' . number_format($schoolFees, 2, ".", ",") . '</td>
</tr>
</tbody>';
$pdf->writeHTML($tbl_head_item . $tbl_item . $tbl_foot_item, FALSE, false, true, false, '');
}
if ($getGender === "Male") {
$classBillItemsForMale = $bill->getClassBillForMale($value["class_name"], $_SESSION["chosen_term"]);
foreach ($classBillItemsForMale as $classBillItemMale) {
if ($getBoardingStatus === "Day Student") {
$schoolFeesMale = $classBillItemMale["day_amount"];
} else {
$schoolFeesMale = $classBillItemMale["boarding_amount"];
}
$tbl_head_item = '<table cellspacing = "1" cellpadding = "0" border = "0">';
$tbl_foot_item = '</table>';
$tbl_item = '';
$tbl_item .= '
<tbody>
<tr style="color: #000;">
<td style="width: 10%;"> </td>
<td style="width: 70%;">' . $classBillItemMale["bill_item"] . '</td>
<td style="text-align: right; width: 10%;">' . number_format($schoolFeesMale, 2, ".", ",") . '</td>
</tr>
</tbody>';
$pdf->writeHTML($tbl_head_item . $tbl_item . $tbl_foot_item, FALSE, false, true, false, '');
}
} else {
$classBillItemsForFemale = $bill->getClassBillForFemale($value["class_name"], $_SESSION["chosen_term"]);
foreach ($classBillItemsForFemale as $classBillItemFemale) {
if ($getBoardingStatus === "Day Student") {
$schoolFeesFemale = $classBillItemFemale["day_amount"];
} else {
$schoolFeesFemale = $classBillItemFemale["boarding_amount"];
}
$tbl_head_item = '<table cellspacing = "1" cellpadding = "0" border = "0">';
$tbl_foot_item = '</table>';
$tbl_item = '';
$tbl_item .= '
<tbody>
<tr style="color: #000;">
<td style="width: 10%;"> </td>
<td style="width: 70%;">' . $classBillItemFemale["bill_item"] . '</td>
<td style="text-align: right; width: 10%;">' . number_format($schoolFeesFemale, 2, ".", ",") . '</td>
</tr>
</tbody>';
$pdf->writeHTML($tbl_head_item . $tbl_item . $tbl_foot_item, FALSE, false, true, false, '');
//$get_term_from_session = $_SESSION["chosen_term"];
//$get_session_class = $_SESSION["selected_class_name"];
// $get_class_memebership = $classMembership ->getClassMembersByClassName($_SESSION["selected_class_name"]);
//
// if( $get_class_memebership){
//
// }
$getTotalBillForClass = $bill ->getTotalStudentCharges( $_SESSION["selected_class_name"],$_SESSION["chosen_term"]);
$tbl_head_itema = '<table cellspacing = "1" cellpadding = "0" border = "0">';
$tbl_foot_itema = '</table>';
$tbl_itema = '';
$tbl_itema.= '
<tbody>
<tr style="color: #000;">
<td style="width: 10%;"> </td>
<td style="width: 70%;">' . 'TOTAL:' . '</td>
<td style="text-align: right; width: 10%;">' . number_format($getTotalBillForClass, 2, ".", ",") . '</td>
</tr>
</tbody>';
$pdf->writeHTML($tbl_head_itema . $tbl_itema . $tbl_foot_itema, FALSE, false, true, false, '');
}
}
}
$pdf->lastPage();
ob_end_clean();
$pdf->Output();
Any time i try to generate a bill i keep getting that error and i dont know where i am wrong too...Can any body please help...

Categories