|
|
|
fpdf ต้องการแสดงข้อมูลออกมาโชว์ ถ้ามีค่าเป็น NULL ให้แสดงค่า '00:00:00' |
|
|
|
|
|
|
|
ใครเคยทำบ้างครับ ช่วยสอนช่วยแนะนำที
Code (PHP)
<?php session_start();?>
<html>
<head>
<title>ThaiCreate.Com PHP PDF</title>
</head>
<? include "ConnectDB/DB_Connect.php";
include "header-engineer.php";
include "session_login.php";
$_SESSION['id_status'];
$_SESSION['id_user'] = $id_user;
?>
<body>
<?
$id = $_POST[user];
require('fpdf.php');
$sql_user = "SELECT jd.id_user, u.name, u.lastname FROM jobdata jd LEFT JOIN user u ON ( jd.id_user = u.id_user ) WHERE u.id_user = $_SESSION[id_user] GROUP BY name";
$result_user = mysql_query($sql_user);
$result_select = mysql_query($sql_user);
if($id!=""){
$sql_users = "SELECT jd.id_user, u.name
FROM jobdata jd
LEFT JOIN user u ON ( jd.id_user = u.id_user )
WHERE jd.id_user = ".$id."
GROUP BY name";
$result_user = mysql_query($sql_users);
}//end if
$result_users = mysql_query($sql_user);
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;
}
//Colored table
function FancyTable($header,$data)
{
//Colors, line width and bold font
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
//Header
$w=array(15,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
$this->Ln();
//Color and font restoration
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
//Data
$fill=false;
foreach($data as $row)
{
$this->Cell($w[0],16,$row[0],'LR',0,'C',$fill);
$this->Cell($w[1],16,$row[1],'LR',0,'C',$fill);
$this->Cell($w[2],16,$row[2],'LR',0,'C',$fill);
$this->Cell($w[3],16,$row[3],'LR',0,'C',$fill);
$this->Cell($w[4],16,$row[4],'LR',0,'C',$fill);
$this->Cell($w[5],16,$row[5],'LR',0,'C',$fill);
$this->Cell($w[6],16,$row[6],'LR',0,'C',$fill);
$this->Cell($w[7],16,$row[7],'LR',0,'C',$fill);
$this->Cell($w[8],16,$row[8],'LR',0,'C',$fill);
$this->Cell($w[9],16,$row[9],'LR',0,'C',$fill);
$this->Cell($w[10],16,$row[10],'LR',0,'C',$fill);
$this->Cell($w[11],16,$row[11],'LR',0,'C',$fill);
$this->Cell($w[12],16,$row[12],'LR',0,'C',$fill);
$this->Cell($w[13],16,$row[13],'LR',0,'C',$fill);
$this->Cell($w[14],16,$row[14],'LR',0,'C',$fill);
$this->Cell($w[15],16,$row[15],'LR',0,'C',$fill);
$this->Ln();
$fill=!$fill;
}
$this->Cell(array_sum($w),0,'','T');
}
}
$pdf=new PDF();
//Column titles
$header=array('Name','M01','M02','M03','M04','M05','M06','M07','I01','I02','I03','I04','I05','T01','AB00','Total');
//Data loading
$row_user=mysql_fetch_array($result_user);
//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("optimizeddb");
$strSQL = "SELECT(SELECT name FROM user WHERE id_user= $_SESSION[id_user]) AS uname,
(SELECT SEC_TO_TIME( SUM(
TIME_TO_SEC( TIMEDIFF( timeend, timestart ) ) ) ) FROM jobdata WHERE id_type=1 AND id_user= $_SESSION[id_user]) AS T1 ,
(SELECT SEC_TO_TIME( SUM(
TIME_TO_SEC( TIMEDIFF( timeend, timestart ) ) ) ) FROM jobdata WHERE id_type=2 AND id_user= $_SESSION[id_user]) AS T2,
(SELECT SEC_TO_TIME( SUM(
TIME_TO_SEC( TIMEDIFF( timeend, timestart ) ) ) ) FROM jobdata WHERE id_type=3 AND id_user= $_SESSION[id_user]) AS T3,
(SELECT SEC_TO_TIME( SUM(
TIME_TO_SEC( TIMEDIFF( timeend, timestart ) ) ) ) FROM jobdata WHERE id_type=4 AND id_user= $_SESSION[id_user]) AS T4,
(SELECT SEC_TO_TIME( SUM(
TIME_TO_SEC( TIMEDIFF( timeend, timestart ) ) ) ) FROM jobdata WHERE id_type=5 AND id_user= $_SESSION[id_user]) AS T5,
(SELECT SEC_TO_TIME( SUM(
TIME_TO_SEC( TIMEDIFF( timeend, timestart ) ) ) ) FROM jobdata WHERE id_type=6 AND id_user= $_SESSION[id_user]) AS T6,
(SELECT SEC_TO_TIME( SUM(
TIME_TO_SEC( TIMEDIFF( timeend, timestart ) ) ) ) FROM jobdata WHERE id_type=7 AND id_user= $_SESSION[id_user]) AS T7,
(SELECT SEC_TO_TIME( SUM(
TIME_TO_SEC( TIMEDIFF( timeend, timestart ) ) ) ) FROM jobdata WHERE id_type=8 AND id_user= $_SESSION[id_user]) AS T8,
(SELECT SEC_TO_TIME( SUM(
TIME_TO_SEC( TIMEDIFF( timeend, timestart ) ) ) ) FROM jobdata WHERE id_type=9 AND id_user= $_SESSION[id_user]) AS T9,
(SELECT SEC_TO_TIME( SUM(
TIME_TO_SEC( TIMEDIFF( timeend, timestart ) ) ) ) FROM jobdata WHERE id_type=10 AND id_user= $_SESSION[id_user]) AS T10,
(SELECT SEC_TO_TIME( SUM(
TIME_TO_SEC( TIMEDIFF( timeend, timestart ) ) ) ) FROM jobdata WHERE id_type=11 AND id_user= $_SESSION[id_user]) AS T11,
(SELECT SEC_TO_TIME( SUM(
TIME_TO_SEC( TIMEDIFF( timeend, timestart ) ) ) ) FROM jobdata WHERE id_type=12 AND id_user= $_SESSION[id_user]) AS T12,
(SELECT SEC_TO_TIME( SUM(
TIME_TO_SEC( TIMEDIFF( timeend, timestart ) ) ) ) FROM jobdata WHERE id_type=13 AND id_user= $_SESSION[id_user]) AS T13,
(SELECT SEC_TO_TIME( SUM(
TIME_TO_SEC( TIMEDIFF( timeend, timestart ) ) ) ) FROM jobdata WHERE id_type=14 AND id_user= $_SESSION[id_user]) AS T14,
(SELECT SEC_TO_TIME( SUM(
TIME_TO_SEC( TIMEDIFF( timeend, timestart ) ) ) ) FROM jobdata WHERE id_user= $_SESSION[id_user]) AS T15";
$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->SetFont('Arial','',10);
//*** Table 3 ***//
$pdf->AddPage();
$pdf->Image('logo3.png',80,8,33);
$pdf->Ln(35);
$pdf->Ln();
$pdf->FancyTable($header,$resultData);
$pdf->Output("MyPDF/MyPDF.pdf","F");
?>
PDF Created Click <a href="MyPDF/MyPDF.pdf">here</a> to Download
</body>
</html>
Tag : PHP
|
|
|
|
|
|
Date :
2015-09-16 10:14:10 |
By :
kendocfc |
View :
866 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|