我很难从postgres数据库中的数据生成PDF文件。
我已经能够正确生成excel文件,但我不能对PDF做同样的事情。
这是我生成的excel。我怎么能这样做,但发送到pdf?
<?php
session_start();
header("Content-Type:application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=QuickList.xls");
header("Pragma: no-cache");
header("Expires: 0");
include_once("C:/webroot/connect.php");
$user=$_SESSION['username'];
//loop the query data to the table in same order as the headers
$sql_data = "SELECT agent, study, ind_no, sponsor, status
FROM dw_regtrack.qlstudies st
LEFT JOIN dw_regtrack.user_studies us ON st.study=us.study_name
WHERE user_name='$user'";
/*$sql_data2="SELECT study, amtrackid, name, pi, status, irbappcr, ohrp, ib, prot, ic, global1572, 1572, ibc, obarac, dsa
FROM dw_regtrack.qlstudysites2";*/
$sql_data2="select study, amtrackid, name, pi, dsa, status,
CASE WHEN irbappcr = '1' THEN 'yes' WHEN irbappcr = '3' THEN 'n/a' ELSE 'no' END as irbappcr,
CASE WHEN ibc = '1' THEN 'yes' WHEN ibc = '3' THEN 'n/a' ELSE 'no' END as ibc,
CASE WHEN obarac = '1' THEN 'yes' WHEN obarac = '3' THEN 'n/a' ELSE 'no' END as obarac,
CASE WHEN ohrp = '1' THEN 'yes' WHEN ohrp = '3' THEN 'n/a' ELSE 'no' END as ohrp,
CASE WHEN ib = '1' THEN 'yes' WHEN ib = '3' THEN 'n/a' ELSE 'no' END as ib,
CASE WHEN prot = '1' THEN 'yes' WHEN prot = '3' THEN 'n/a' ELSE 'no' END as prot,
CASE WHEN ic = '1' THEN 'yes' WHEN ic = '3' THEN 'n/a' ELSE 'no' END as ic,
CASE WHEN global1572 = '1' THEN 'yes' WHEN global1572 = '3' THEN 'n/a' ELSE 'no' END as global1572,
CASE WHEN \"1572\" = '1' THEN 'yes' WHEN \"1572\" = '3' THEN 'n/a' ELSE 'no' END as \"1572\"
FROM dw_regtrack.qlstudysites2";
/*$sql_data3="SELECT amtrackid, labid, name, cap, clia, lnv
FROM dw_regtrack.qlstudysitelabs";*/
$sql_data3="SELECT amtrackid,labid,name,
CASE WHEN cap = '1' THEN 'yes' WHEN cap = '3' THEN 'n/a' ELSE 'no' END as cap,
CASE WHEN clia = '1' THEN 'yes' WHEN clia = '3' THEN 'n/a' ELSE 'no' END as clia,
CASE WHEN lnv = '1' THEN 'yes' WHEN lnv = '3' THEN 'n/a' ELSE 'no' END as lnv
FROM dw_regtrack.qlstudysitelabs";
/*$sql_data4="SELECT amtrackid, personid, name, cv, ml, fd, hspt, dot, pisort
FROM dw_regtrack.qlstudysiteinvests2";*/
$sql_data4="SELECT amtrackid,personid, name,
CASE WHEN cv = '1' THEN 'yes' WHEN cv = '3' THEN 'n/a' ELSE 'no' END as cv,
CASE WHEN ml = '1' THEN 'yes' WHEN ml = '3' THEN 'n/a' ELSE 'no' END as ml,
CASE WHEN fd = '1' THEN 'yes' WHEN fd = '3' THEN 'n/a' ELSE 'no' END as fd,
CASE WHEN dot = '1' THEN 'yes' WHEN dot = '3' THEN 'n/a' ELSE 'no' END as dot,
CASE WHEN hspt = '1' THEN 'yes' WHEN hspt = '3' THEN 'n/a' ELSE 'no' END as hspt,pisort
FROM dw_regtrack.qlstudysiteinvests2";
$result=pg_query($sql_data);
while ($row = pg_fetch_array($result, NULL, PGSQL_ASSOC)){
echo implode("\t", array('Agent', 'Study', 'IND No', 'IND Sponsor', 'Current Status'))."\r\n";
echo implode("\t", array($row['agent'], $row['study'], $row['ind_no'],$row['sponsor'], $row['status'])) . "\r\n";
$result2=pg_query($sql_data2." WHERE study = '".$row['study']."'");
while ($row2=pg_fetch_array($result2, NULL, PGSQL_ASSOC))
{
echo implode("\t", array('','Site', 'PI', 'Status', 'IRBappcr', 'OHRP', 'IB', 'PROT', 'IC', 'Global1572', '1572', 'IBC', 'OBARAC', 'DSA'))."\r\n";
echo implode("\t", array('',$row2['name'], $row2['pi'], $row2['status'], $row2['irbappcr'], $row2['ohrp'], $row2['ib'], $row2['prot'], $row2['ic'], $row2['global1572'], $row2['1572'], $row2['ibc'], $row2['obarac'], $row2['dsa']))."\r\n";
$result3=pg_query($sql_data3." WHERE amtrackid= '".$row2['amtrackid']."'");
echo implode("\t", array('','','Lab', 'CAP', 'CLIA', 'LNV'))."\r\n";
while ($row3=pg_fetch_array($result3, NULL, PGSQL_ASSOC)){
echo implode("\t", array('','',$row3['name'], $row3['cap'], $row4['clia'],$row4['lnv']))."\r\n";
}
$result4=pg_query($sql_data4." WHERE amtrackid= '".$row2['amtrackid']."'");
echo implode("\t", array('','','Investigator', 'CV', 'ML', 'FD', 'HSPT', 'DOT'))."\r\n";
while ($row4=pg_fetch_array($result4, NULL, PGSQL_ASSOC)){
echo implode("\t", array('','',$row4['name'], $row4['cv'], $row4['ml'],$row4['fd'], $row4['hspt'],$row4['dot']))."\r\n";
}
}
}
?>