Below are the features implemented in the below code
1) Implementing LINQ in PHP
2) Generating PDF in PHP using FPDF
3) Using Arrays in PHP
4) Using list in PHP
5) Oracle connection using PHP
You need to download fpdf & D3Linq (phpclasses.org) to implement the below code.
<?php
error_reporting(0);
set_time_limit(0);
date_default_timezone_set('Asia/Calcutta');
require('FPDF/fpdf.php');
include 'D3Linq.php';
$a=new D3Linq();
$b=new D3Linq();
$results_array = array();
$results_array2 = array();
$db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = HOSTNAME)(PORT = 1521)))(CONNECT_DATA=(SID=DBNAME)))";
if ($conn =OCILogon("USERNAME", "PWD", $db)) {
//OCILogoff($c);
} else {
$err = OCIError();
}
$query = "SELECT * from TABLE WHERE ACTIVESTATUS=1";
$stid = OCIParse($conn, $query);
OCIExecute($stid, OCI_DEFAULT);
$pdf = new FPDF();
$ImgStartRow = 45;
$ImgStartRowright = 45;
$StartRow = 85;
$startrowright = 85;
$count=0;
while ($row = oci_fetch_object($stid)) {
$results_array[$row->GROUPID] = $row->GROUPID;
$results_array2[$row->ID] = 'GROUPID~'.$row->GROUPID.'~'.$row->EMPLOYEENAME.'~'.$row->EMPDOJ.'~'.$row->EMPSALARY.'~'.$row->EMPNAME.'~'.$row->EMPGENDER.'~'.$row->EMPAGE;
}//while
$pagecount=0;
$a->Query("SELECT key ElementName, value Value FROM results_array ");
while ($data=$a->fetch_assoc()){
if(($pagecount % 10) == 0)
{
//ADD PAGE
$pdf->AddPage();
$ImgStartRow = 5;
$ImgStartRowright = 5;
$StartRow = 19;
$startrowright=4;
}//if
//DISPLAY DATA
$phname="";
$dojj="";
$pdf->Image('images/1.jpg',5,$ImgStartRow );
$pdf->Image('images/2.jpg',95,$ImgStartRow );
//IMPLEMENTING GROUP BY USING LINQ IN PHP
$b->Query("SELECT value Details FROM results_array2 where value like 'GROUPID~".$data['Value']."~%'");
while ($GrpData=$b->fetch_assoc()){
list($ignore, $groupid, $empname, $empdoj, $empsalary,$employeename,$empgender,$empage) = explode("~", $GrpData['Details']);
$count++;
if($pagecount %2 == 0)
{
$pdf->SetFont('Arial','',8); $pdf->Text(10,$StartRow,$empname); $StartRow += 6;
$pdf->SetFont('Arial','',6); $pdf->Text(10,$StartRow,$empdoj); $StartRow += 6;
}
else
{
$pdf->SetFont('Arial','',8); $pdf->Text(100,$StartRow,$empname); $StartRow += 6;
$pdf->SetFont('Arial','',6); $pdf->Text(100,$StartRow,$empdoj); $StartRow += 6;
}
//PDF GENERATION END
}//inner while for grouping
//DISPLAY DATA END
if($count == 1)
$finalheight = 15;
else if($count == 2)
$finalheight = 15;
if($count == 1)
$finalheightright = 20;
else if($count == 2)
$finalheightright = 15;
$StartRow+=$finalheight;
$startrowright+=$finalheightright;
// FOR ALIGNING NO OF 5 IMAGES (ROW) PER PAGE
$ImgStartRow +=59;
$ImgStartRowright +=59;
$count=0;
$pagecount++;
}//while key
$pdf->SetY(-8);
$pdf->SetFont('Times','I',8);
header("Content-Transfer-Encoding", "binary");
header('Cache-Control: maxage=600000'); //Adjust maxage appropriately
header('Pragma: public');
$pdf->Output('GENARTEDPDF.pdf', 'D');
$pdf->Output();
?>
1) Implementing LINQ in PHP
2) Generating PDF in PHP using FPDF
3) Using Arrays in PHP
4) Using list in PHP
5) Oracle connection using PHP
You need to download fpdf & D3Linq (phpclasses.org) to implement the below code.
<?php
error_reporting(0);
set_time_limit(0);
date_default_timezone_set('Asia/Calcutta');
require('FPDF/fpdf.php');
include 'D3Linq.php';
$a=new D3Linq();
$b=new D3Linq();
$results_array = array();
$results_array2 = array();
$db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = HOSTNAME)(PORT = 1521)))(CONNECT_DATA=(SID=DBNAME)))";
if ($conn =OCILogon("USERNAME", "PWD", $db)) {
//OCILogoff($c);
} else {
$err = OCIError();
}
$query = "SELECT * from TABLE WHERE ACTIVESTATUS=1";
$stid = OCIParse($conn, $query);
OCIExecute($stid, OCI_DEFAULT);
$pdf = new FPDF();
$ImgStartRow = 45;
$ImgStartRowright = 45;
$StartRow = 85;
$startrowright = 85;
$count=0;
while ($row = oci_fetch_object($stid)) {
$results_array[$row->GROUPID] = $row->GROUPID;
$results_array2[$row->ID] = 'GROUPID~'.$row->GROUPID.'~'.$row->EMPLOYEENAME.'~'.$row->EMPDOJ.'~'.$row->EMPSALARY.'~'.$row->EMPNAME.'~'.$row->EMPGENDER.'~'.$row->EMPAGE;
}//while
$pagecount=0;
$a->Query("SELECT key ElementName, value Value FROM results_array ");
while ($data=$a->fetch_assoc()){
if(($pagecount % 10) == 0)
{
//ADD PAGE
$pdf->AddPage();
$ImgStartRow = 5;
$ImgStartRowright = 5;
$StartRow = 19;
$startrowright=4;
}//if
//DISPLAY DATA
$phname="";
$dojj="";
$pdf->Image('images/1.jpg',5,$ImgStartRow );
$pdf->Image('images/2.jpg',95,$ImgStartRow );
//IMPLEMENTING GROUP BY USING LINQ IN PHP
$b->Query("SELECT value Details FROM results_array2 where value like 'GROUPID~".$data['Value']."~%'");
while ($GrpData=$b->fetch_assoc()){
list($ignore, $groupid, $empname, $empdoj, $empsalary,$employeename,$empgender,$empage) = explode("~", $GrpData['Details']);
$count++;
if($pagecount %2 == 0)
{
$pdf->SetFont('Arial','',8); $pdf->Text(10,$StartRow,$empname); $StartRow += 6;
$pdf->SetFont('Arial','',6); $pdf->Text(10,$StartRow,$empdoj); $StartRow += 6;
}
else
{
$pdf->SetFont('Arial','',8); $pdf->Text(100,$StartRow,$empname); $StartRow += 6;
$pdf->SetFont('Arial','',6); $pdf->Text(100,$StartRow,$empdoj); $StartRow += 6;
}
//PDF GENERATION END
}//inner while for grouping
//DISPLAY DATA END
if($count == 1)
$finalheight = 15;
else if($count == 2)
$finalheight = 15;
if($count == 1)
$finalheightright = 20;
else if($count == 2)
$finalheightright = 15;
$StartRow+=$finalheight;
$startrowright+=$finalheightright;
// FOR ALIGNING NO OF 5 IMAGES (ROW) PER PAGE
$ImgStartRow +=59;
$ImgStartRowright +=59;
$count=0;
$pagecount++;
}//while key
$pdf->SetY(-8);
$pdf->SetFont('Times','I',8);
header("Content-Transfer-Encoding", "binary");
header('Cache-Control: maxage=600000'); //Adjust maxage appropriately
header('Pragma: public');
$pdf->Output('GENARTEDPDF.pdf', 'D');
$pdf->Output();
?>
No comments:
Post a Comment