I use FPDF to create a PDF file that data is extracted from a MySQL database. And the table is created with two headings for the main columns "Username" and "Total time spent."
<?php
require('../Libraries/fpdf/fpdf.php');
include_once ('../iConnect/handShake.php');
class h4PDF extends FPDF{
function Header(){
$this->Image('../../images/logo.png', 10,6,30);
$this->SetFont('Arial', 'B', 12);
$this->Cell(80);
$this->Cell(50, 10, 'Total Spent Time', 0, 0,'C');
$this->Ln(10);
}
}
$getTot = "SELECT userlogin.uName, SEC_TO_TIME(SUM(TIME_TO_SEC(timeSpent))) AS totTime FROM usertimetrack
LEFT JOIN userlogin ON usertimetrack.usrId = userlogin.uId WHERE jDate = :jdate GROUP BY usrId";
$getTotQuery = $dbConnect -> prepare($getTot);
$getTotQuery -> bindParam('jdate', $_REQUEST["date"]);
$getTotQuery -> execute();
$pdf = new h4PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','', 14);
$pdf->SetFillColor(255,0,0);
$pdf->SetTextColor(255);
$pdf->SetDrawColor(128,0,0);
$pdf->SetLineWidth(.3);
$pdf->SetFont('','B');
$pdf->SetX(70);
$pdf->Cell(40,6,'User Name',1,0,'C',1);
$pdf->SetX(105);
$pdf->SetX(110);
$pdf->Cell(42,6,'Total Spent Time',1,0,'C',1);
$pdf->Ln();
$pdf->SetFillColor(224,235,255);
$pdf->SetTextColor(0);
$pdf->SetFont('');
$fill = false;
while ($getTotRow = $getTotQuery -> fetch(PDO::FETCH_ASSOC)){
$uName = $getTotRow["uName"];
$totTime = $getTotRow["totTime"];
$pdf->SetX(70);
$pdf->Cell(40,6,$uName,'LR',0,'C',$fill);
$pdf->SetX(105);
$pdf->SetX(110);
$pdf->Cell(42,6,$totTime ,'LR',0,'C',$fill);
$pdf->Ln();
$fill = !$fill;
}
$pdf->SetX(70);
$pdf->Cell(82,0,'','T');
$pdf->Output();
In the current code, I can create a table, but this code only prints the column heading of the table on the first page, only actually at the beginning of the table, and the rest will be filled with data that continues until the data ends. I want to repeat these 2 headings on each page at the beginning of the table on each page.
I tried to do something like this script, but ended up creating an infinity loop.
, , , , . , .
-, , , , , , script.
** : ** kastriotcunaku , :
<?php
require('../Libraries/fpdf/fpdf.php');
include_once ('../iConnect/handShake.php');
class h4PDF extends FPDF{
function Header(){
$this->Image('../../images/logo.png', 10,6,30);
$this->SetFont('Arial', 'B', 12);
$this->Cell(80);
$this->Cell(50, 10, 'Total Spent Time', 0, 0,'C');
$this->Ln(10);
$this->SetFont('Arial','', 14);
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetX(74);
$this->Cell(40,6,'User Name',1,0,'C',1);
$this->SetX(109);
$this->SetX(114);
$this->Cell(42,6,'Total Spent Time',1,0,'C',1);
$this->Ln();
}
}
$getTot = "SELECT userlogin.uName, SEC_TO_TIME(SUM(TIME_TO_SEC(timeSpent))) AS totTime FROM usertimetrack
LEFT JOIN userlogin ON usertimetrack.usrId = userlogin.uId WHERE jDate = :jdate GROUP BY usrId";
$getTotQuery = $dbConnect -> prepare($getTot);
$getTotQuery -> bindParam('jdate', $_REQUEST["date"]);
$getTotQuery -> execute();
$pdf = new h4PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','', 14);
$pdf->SetFillColor(255,0,0);
$pdf->SetTextColor(255);
$pdf->SetDrawColor(128,0,0);
$pdf->SetLineWidth(.1);
$pdf->SetFont('','B');
$pdf->SetFillColor(224,235,255);
$pdf->SetTextColor(0);
$pdf->SetFont('');
$fill = false;
while ($getTotRow = $getTotQuery -> fetch(PDO::FETCH_ASSOC)){
$uName = $getTotRow["jDate"];
$totTime = $getTotRow["timeSpent"];
$pdf->SetX(74);
$pdf->Cell(40,6,$uName,'1',0,'C',$fill);
$pdf->SetX(109);
$pdf->SetX(114);
$pdf->Cell(42,6,$totTime ,'1',0,'C',$fill);
$pdf->Ln();
$fill = !$fill;
}
$pdf->Output();
, while, , 0.1, .