Hello, we have a system used for our HR. One of the features is providing service records to our employees. We have already the data but the problem is when we retrieve and display those service records specially if the employee's service records reached 2 or 3 pages the last date showed on the first page will again show on the 2nd page. I hope your generous heart will able to help me. Thanks in advance
Note: If employee's service record is one page only we don't have problem.
How do you do your DB query? If you are saying the last record of page 1 is showing up as first record of page 2, sounds like issue with calculating LIMIT attributes and you just need to pump figures up by one.
(11-29-2018, 03:17 AM)Pertti Wrote: How do you do your DB query? If you are saying the last record of page 1 is showing up as first record of page 2, sounds like issue with calculating LIMIT attributes and you just need to pump figures up by one.
Code:
foreach($rows as $row)
{
$pdf->SetFont('Arial', '', 11);
$pdf->SetX(10);
//$pi = new Personal();
//$pi->get_by_employee_id( $employee_id );
//print_r($personal_info);
// initiate FPDI
$pdf = new FPDI('P','mm','Letter');
// add a page
$pdf->AddPage();
// set the sourcefile
//$pdf->setSourceFile('dtr/template/service_record/service_record.pdf');
// import page 1
//$tplIdx = $pdf->importPage(1);
// use the imported page and place it at point 10,10 with a width of 100 mm
//$pdf->useTemplate($tplIdx, 1, 1, 210);
// now write some text above the imported page
$pdf->SetFont('Arial');
$pdf->SetTextColor(0,0,0);
$pdf->SetXY(15, 60);
$pdf->SetFont('Arial', '', 16);
$pdf->Cell(0,3,"Employee's Service Record" ,'',1,'C',false);
$this->load->library('mpdf', $params); // LOAD a stylesheet $stylesheet = file_get_contents(base_url().'css/mpdf/mpdfstyletables.css'); $this->mpdf->WriteHTML($stylesheet,1); // The parameter 1 tells that this is css/style only and no body/html/text $this->mpdf->WriteHTML($html);
$office = new Office_m();
foreach($rows as $row) { $office->get_by_office_id($row->office_id); $type_employment = $this->options->type_employment();
$birth_date = $row->birth_date;
if ( $row->birth_date == '0000-00-00') { $birth_date = ''; }
// initiate FPDI $pdf = new FPDI('L','mm','Letter');
// add a page $pdf->AddPage(); // set the sourcefile //$pdf->setSourceFile('dtr/template/service_record/service_record.pdf'); // import page 1 //$tplIdx = $pdf->importPage(1); // use the imported page and place it at point 10,10 with a width of 100 mm //$pdf->useTemplate($tplIdx, 1, 1, 210); // now write some text above the imported page $pdf->SetFont('Arial'); $pdf->SetTextColor(0,0,0);
$pdf->Cell(0,8,"Emp ID Name Sex Position/Designation Office Employment Status Salary Grade Eligibility Education Birth Day Address" ,'1',1,'L',false);
$pdf->Ln(4);
$i = 1;
$this->load->helper('text');
//$pdf->Cell(30,12, word_wrap('msayado maahhn ndhah ahhhehe so ano gagawin mo now', 10) ,'1',1,'L',false); //$pdf->MultiCell(30,3,word_wrap("hello this is a sample nlong text with line break ", 15) ,'1',1,'L',false); //$pdf->MultiCell(30,3,word_wrap("hello this is a sample nlong text with line break ", 15) ,'0',1,'L',false);
foreach($rows as $row) { $pdf->SetFont('Arial', '', 11); $pdf->SetX(10);
$this->mpdf->mirrorMargins = 1; // Use different Odd/Even headers and footers and mirror margins
$stylesheet = file_get_contents(base_url().'css/mpdf/mpdfstyletables.css'); $this->mpdf->WriteHTML($stylesheet,1); // The parameter 1 tells that this is css/style only and no
function employees($office_id = '') { header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
12-05-2018, 12:42 PM (This post was last modified: 12-05-2018, 12:45 PM by jreklund.)
@jelz2018: You added a fair amount of code, it can take time to solve. Your problem resides here. You are first printing your row, checking if it's a new page 18/37 and printing the row again. Before ending the loop and getting a new row.
PHP Code:
$i = 0; foreach ($rows as $row) { $number_character = strlen( $row->designation.$row->salary.$row->salary. $row->office_entity.$row->lwop.$row->separation_date.$row->separation_cause ); $html .='<tr> <td align="center">'.$row->date_from.'</td> <td align="center">'.$row->date_to.'</td> <td align="left">'.$row->designation.'</td> <td align="left">'.$row->status.'</td> <td align="right">'.$row->salary.'</td> <td align="left">'.$row->office_entity.'</td> <td align="left">'.$row->lwop.'</td> <td align="left">'.$row->separation_date.'</td> <td align="left" style="font-size:7">'.$row->separation_cause.'</td> </tr>'; // Second page if ( $i == 18) { $html .='</table>'; // close the table $html .='<pagebreak />'.$service; $html .='<tr> <td align="center">'.$row->date_from.'</td> <td align="center">'.$row->date_to.'</td> <td align="left">'.$row->designation.'</td> <td align="left">'.$row->status.'</td> <td align="right">'.$row->salary.'</td> <td align="left">'.$row->office_entity.'</td> <td align="left">'.$row->lwop.'</td> <td align="left">'.$row->separation_date.'</td> <td align="left">'.$row->separation_cause.'</td> </tr>'; } // If there is third page if ( $i == 37) { $html .='</table>'; // close the table $html .='<pagebreak />'.$service; $html .='<tr> <td align="center">'.$row->date_from.'</td> <td align="center">'.$row->date_to.'</td> <td align="left">'.$row->designation.'</td> <td align="left">'.$row->status.'</td> <td align="right">'.$row->salary.'</td> <td align="left">'.$row->office_entity.'</td> <td align="left">'.$row->lwop.'</td> <td align="left">'.$row->separation_date.'</td> <td align="left">'.$row->separation_cause.'</td> </tr>'; } $i++;
}
It can be solved dynamically by this, as it's the best solution. Or you just can delete your <tr><td>... inside your if statements. This code checks and recounts $i after 19, so after 18 $i will think it's 0 again and start over. This way you can have hundreds of pages and not worry about adding if( $i == 341 ).
You should however count $rows and add a check to if( $i++%19 == 18 ), so that it won't print on the last item. So that you don't get an empty page. That can be your homework. :-)
(12-05-2018, 12:42 PM)jreklund Wrote: @jelz2018: You added a fair amount of code, it can take time to solve. Your problem resides here. You are first printing your row, checking if it's a new page 18/37 and printing the row again. Before ending the loop and getting a new row.
PHP Code:
$i = 0; foreach ($rows as $row) { $number_character = strlen( $row->designation.$row->salary.$row->salary. $row->office_entity.$row->lwop.$row->separation_date.$row->separation_cause ); $html .='<tr> <td align="center">'.$row->date_from.'</td> <td align="center">'.$row->date_to.'</td> <td align="left">'.$row->designation.'</td> <td align="left">'.$row->status.'</td> <td align="right">'.$row->salary.'</td> <td align="left">'.$row->office_entity.'</td> <td align="left">'.$row->lwop.'</td> <td align="left">'.$row->separation_date.'</td> <td align="left" style="font-size:7">'.$row->separation_cause.'</td> </tr>'; // Second page if ( $i == 18) { $html .='</table>'; // close the table $html .='<pagebreak />'.$service; $html .='<tr> <td align="center">'.$row->date_from.'</td> <td align="center">'.$row->date_to.'</td> <td align="left">'.$row->designation.'</td> <td align="left">'.$row->status.'</td> <td align="right">'.$row->salary.'</td> <td align="left">'.$row->office_entity.'</td> <td align="left">'.$row->lwop.'</td> <td align="left">'.$row->separation_date.'</td> <td align="left">'.$row->separation_cause.'</td> </tr>'; } // If there is third page if ( $i == 37) { $html .='</table>'; // close the table $html .='<pagebreak />'.$service; $html .='<tr> <td align="center">'.$row->date_from.'</td> <td align="center">'.$row->date_to.'</td> <td align="left">'.$row->designation.'</td> <td align="left">'.$row->status.'</td> <td align="right">'.$row->salary.'</td> <td align="left">'.$row->office_entity.'</td> <td align="left">'.$row->lwop.'</td> <td align="left">'.$row->separation_date.'</td> <td align="left">'.$row->separation_cause.'</td> </tr>'; } $i++;
}
It can be solved dynamically by this, as it's the best solution. Or you just can delete your <tr><td>... inside your if statements. This code checks and recounts $i after 19, so after 18 $i will think it's 0 again and start over. This way you can have hundreds of pages and not worry about adding if( $i == 341 ).
You should however count $rows and add a check to if( $i++%19 == 18 ), so that it won't print on the last item. So that you don't get an empty page. That can be your homework. :-)
Wow. Thanks for your generous heart for helping me. It's highly appreciated. Thanks a lot.
As I've tried your solution sir but still the last entry of the first page repeated in the second page as a 1st entry and also it show only 5 entries per page.
That's strange. It dosen't stop the loop. How many pages did you get? More than 3 I take it?
Just for the sake of it. Try your code and delete the extra <tr> inside your if statements. In case I made an error on my if statement.