|
|
Code (PHP)
require('fpdf.php');
define('FPDF_FONTPATH','font/');
class PDF extends FPDF
{
//Load data
function LoadData($file)
{
//Read file lines
$lines=file($file);
$data=array();
foreach($lines as $line)
$data[]=explode(';',chop($line));
return $data;
}
//Simple table
function BasicTable($header,$header2,$header3,$data)
{
//Header
$w=array(15,30,30,71,71,51);
//Header
$this->Cell($w[0],18,iconv('UTF-8', 'TIS-620', $header[0]),1,0,'C');
$this->Cell($w[1],9,iconv('UTF-8', 'TIS-620', $header[1]),1,0,'C');
$this->Cell($w[2],9,iconv('UTF-8', 'TIS-620', $header[2]),1,0,'C');
$this->Cell($w[3],9,iconv('UTF-8', 'TIS-620', $header[3]),1,0,'C');
$this->Cell($w[4],9,iconv('UTF-8', 'TIS-620', $header[4]),1,0,'C');
$this->Cell($w[5],9,iconv('UTF-8', 'TIS-620', $header[5]),1,0,'C');
//for($i=0;$i<count($header);$i++)
// $this->Cell($w[$i],7,iconv('UTF-8', 'TIS-620', $header[$i]),1,0,'C');
$this->Ln();
//Header
$w1=array(25,8,8,14,10,10,10,16,12,14,16,13,16,12,14,16,13,25,26,15);
//Header
//$this->Cell($w1[0],0,iconv('UTF-8', 'TIS-620', $header2[0]));
$this->Cell($w1[19],0,iconv('UTF-8', 'TIS-620', $header2[19]));
$this->Cell($w1[1],9,iconv('UTF-8', 'TIS-620', $header2[1]),1,0,'C');
$this->Cell($w1[2],9,iconv('UTF-8', 'TIS-620', $header2[2]),1,0,'C');
$this->Cell($w1[3],9,iconv('UTF-8', 'TIS-620', $header2[3]),1,0,'C');
$this->Cell($w1[4],9,iconv('UTF-8', 'TIS-620', $header2[4]),1,0,'C');
$this->Cell($w1[5],9,iconv('UTF-8', 'TIS-620', $header2[5]),1,0,'C');
$this->Cell($w1[6],9,iconv('UTF-8', 'TIS-620', $header2[6]),1,0,'C');
$this->Cell($w1[7],9,iconv('UTF-8', 'TIS-620', $header2[7]),1,0,'C');
$this->Cell($w1[8],9,iconv('UTF-8', 'TIS-620', $header2[8]),1,0,'C');
$this->Cell($w1[9],9,iconv('UTF-8', 'TIS-620', $header2[9]),1,0,'C');
$this->Cell($w1[10],9,iconv('UTF-8', 'TIS-620', $header2[10]),1,0,'C');
$this->Cell($w1[11],9,iconv('UTF-8', 'TIS-620', $header2[11]),1,0,'C');
$this->Cell($w1[12],9,iconv('UTF-8', 'TIS-620', $header2[12]),1,0,'C');
$this->Cell($w1[13],9,iconv('UTF-8', 'TIS-620', $header2[13]),1,0,'C');
$this->Cell($w1[14],9,iconv('UTF-8', 'TIS-620', $header2[14]),1,0,'C');
$this->Cell($w1[15],9,iconv('UTF-8', 'TIS-620', $header2[15]),1,0,'C');
$this->Cell($w1[16],9,iconv('UTF-8', 'TIS-620', $header2[16]),1,0,'C');
$this->Cell($w1[17],9,iconv('UTF-8', 'TIS-620', $header2[17]),1,0,'C');
$this->Cell($w1[18],9,iconv('UTF-8', 'TIS-620', $header2[18]),1,0,'C');
//for($i=0;$i<count($header2);$i++)
//$this->Cell($w[$i],7,$header[$i],1,0,'C');
//$this->Cell($w1[$i+1],7,iconv('UTF-8', 'TIS-620', $header2[$i+1]),1,0,'C');
$this->Ln();
//Data
foreach ($data as $eachResult)
{
// $this->Cell(25,7,$eachResult["name_hos"],1);
$this->Cell(15,7,$eachResult["Month"]."/".$eachResult["Year"],1,0,'C');
$this->Cell(8,7,$eachResult["OPD"],1,0,'C');
$this->Cell(8,7,$eachResult["ER_IPD"],1,0,'C');
$this->Cell(14,7,$eachResult["Refer_sum"],1,0,'C');
$this->Cell(10,7,$eachResult["Emergency"],1,0,'C');
$this->Cell(10,7,$eachResult["Urgency"],1,0,'C');
$this->Cell(10,7,$eachResult["Non_urgency"],1,0,'C');
$this->Cell(16,7,$eachResult["IN_Province"],1,0,'C');
$this->Cell(12,7,$eachResult["IN_Zone"],1,0,'C');
$this->Cell(14,7,$eachResult["Out_Zone"],1,0,'C');
$this->Cell(16,7,$eachResult["Center"],1,0,'C');
$this->Cell(13,7,$eachResult["Sum_Solder"],1,0,'C');
$this->Cell(16,7,$eachResult["Scorn_IN_Province"],1,0,'C');
$this->Cell(12,7,$eachResult["Scorn_IN_Zone"],1,0,'C');
$this->Cell(14,7,$eachResult["Scorn_Out_Zone"],1,0,'C');
$this->Cell(16,7,$eachResult["Scorn_Center"],1,0,'C');
$this->Cell(13,7,$eachResult["Scorn_Sum"],1,0,'C');
$this->Cell(25,7,$eachResult["Min_30"],1,0,'C');
$this->Cell(26,7,$eachResult["Max_30"],1,0,'C');
$this->Ln();
}
//$this->Ln();
//Header
$w2=array(15,8,8,14,10,10,10,16,12,14,16,13,16,12,14,16,13,25,26,15);
//Header
$this->Cell($w2[0],9,iconv('UTF-8', 'TIS-620','รวม'),1,0,'C');
//$this->Cell($w2[19],9,iconv('UTF-8', 'TIS-620', $header3[19]),1,0,'C');
$this->Cell($w2[1],9,iconv('UTF-8', 'TIS-620', $header3[1]),1,0,'C');
$this->Cell($w2[2],9,iconv('UTF-8', 'TIS-620', $header3[2]),1,0,'C');
$this->Cell($w2[3],9,iconv('UTF-8', 'TIS-620', $header3[3]),1,0,'C');
$this->Cell($w2[4],9,iconv('UTF-8', 'TIS-620', $header3[4]),1,0,'C');
$this->Cell($w2[5],9,iconv('UTF-8', 'TIS-620', $header3[5]),1,0,'C');
$this->Cell($w2[6],9,iconv('UTF-8', 'TIS-620', $header3[6]),1,0,'C');
$this->Cell($w2[7],9,iconv('UTF-8', 'TIS-620', $header3[7]),1,0,'C');
$this->Cell($w2[8],9,iconv('UTF-8', 'TIS-620', $header3[8]),1,0,'C');
$this->Cell($w2[9],9,iconv('UTF-8', 'TIS-620', $header3[9]),1,0,'C');
$this->Cell($w2[10],9,iconv('UTF-8', 'TIS-620', $header3[10]),1,0,'C');
$this->Cell($w2[11],9,iconv('UTF-8', 'TIS-620', $header3[11]),1,0,'C');
$this->Cell($w2[12],9,iconv('UTF-8', 'TIS-620', $header3[12]),1,0,'C');
$this->Cell($w2[13],9,iconv('UTF-8', 'TIS-620', $header3[13]),1,0,'C');
$this->Cell($w2[14],9,iconv('UTF-8', 'TIS-620', $header3[14]),1,0,'C');
$this->Cell($w2[15],9,iconv('UTF-8', 'TIS-620', $header3[15]),1,0,'C');
$this->Cell($w2[16],9,iconv('UTF-8', 'TIS-620', $header3[16]),1,0,'C');
$this->Cell($w2[17],9,iconv('UTF-8', 'TIS-620', $header3[17]),1,0,'C');
$this->Cell($w2[18],9,iconv('UTF-8', 'TIS-620', $header3[18]),1,0,'C');
$this->Ln();
}
}
$pdf=new PDF(L,mm,A4);
//Column titles
$header=array('เดือน / ปี','ข้อมูล Refer','ระดับความรุนแรง','การประสานงาน','การถูกปฏิเสธ','เวลาประสานงาน');
$header2=array(' ','In','Out','ทั้งหมด','E','U','N','ในจังหวัด','ในเขต','ข้ามเขต','ส่วนกลาง','ทั้งหมด','ในจังหวัด','ในเขต','ข้ามเขต','ส่วนกลาง','ทั้งหมด','ภายใน 30 นาที','มากกว่า 30 นาที');
$header3=array('',$t_OPD,$t_ER_IPD,$t_Refer_sum,$t_Emergency,$t_Urgency,$t_Non_urgency,$t_IN_Province,$t_IN_Zone,$t_Out_Zone,$t_Center,$t_Sum_Solder
,$t_Scorn_IN_Province,$t_Scorn_IN_Zone,$t_Scorn_Out_Zone,$t_Scorn_Center,$t_Scorn_Sum,$t_Min_30,$t_Max_30);
//Data loading
//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","root","123123") or die("Error Connect to Database");
$objDB = mysql_select_db("ntdb101_db");
mysql_query("SET NAMES 'tis620' ");
$strSQL = "SELECT DISTINCT `user`.`name_hos`, `refer`.`Month`, `refer`.`Year`, `refer`.`Refer_sum`,
`refer`.`OPD`, `refer`.`ER_IPD`, `refer`.`Emergency`, `refer`.`Urgency`,
`refer`.`Non_urgency`, `refer`.`Sum_Solder`, `refer`.`IN_Province`,
`refer`.`IN_Zone`, `refer`.`Out_Zone`, `refer`.`Center`, `refer`.`Scorn_Sum`,
`refer`.`Min_30`, `refer`.`Max_30`, `refer`.`Scorn_IN_Province`,
`refer`.`Scorn_IN_Zone`, `refer`.`Scorn_Out_Zone`, `refer`.`Scorn_Center`,
`refer`.`Refer_id`
FROM
`refer` INNER JOIN
`user` ON `refer`.`user_id` = `user`.`user_id` WHERE refer.user_id = user.username AND refer.user_id='". $_SESSION["username"]."' AND refer.Unit=1 order by refer.Year desc,refer.Month desc limit $start,$limit";
$objQuery = mysql_query($strSQL);
$resultData = array();
for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
$result = mysql_fetch_array($objQuery);
array_push($resultData,$result);
}
//************************//
$pdf->AddFont('angsa','','angsa.php');
$pdf->SetFont('angsa','',16);
//*** Table 1 ***//
$pdf->AddPage();
$pdf->Image('logo.png',120,8,35);
$pdf->Text( 98 ,50 ,iconv('UTF-8', 'TIS-620', 'ข้อมูล'.$objResult["name_hos"]));
$pdf->Ln(45);
$pdf->BasicTable($header,$header2,$header3,$resultData);
$pdf->Output("MyPDF/MyPDF2.pdf","F");
จากcode ข้างบน ต้องใส่ rows%12 == 0 ต้องไหนครับฝากพี่วิน ระบุให้หน่อยครับๆ ขอบคุนมากน่ะครับ
|
|
|
|
|
Date :
2012-07-08 10:58:37 |
By :
noi014 |
|
|
|
|
|
|
|
|