Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql、Php到PDF_Php_Mysql_Pdf_Fpdf - Fatal编程技术网

Mysql、Php到PDF

Mysql、Php到PDF,php,mysql,pdf,fpdf,Php,Mysql,Pdf,Fpdf,我使用fpdf将php和mysql查询结果导出为pdf 代码如下: $query = mysql_query("SELECT CONCAT (u.firstname, ' ', u.lastname) AS Member, co.fullname, x.name, SEC_TO_TIME(SUM(TIME_TO_SEC(msst.value))) AS Time, CONCAT(ROUND(gg.finalgrade / gg.rawgrademax * 100 ,0), '%') AS Per

我使用fpdf将php和mysql查询结果导出为pdf

代码如下:

$query = mysql_query("SELECT CONCAT (u.firstname, ' ', u.lastname) AS Member, co.fullname, x.name, SEC_TO_TIME(SUM(TIME_TO_SEC(msst.value))) AS Time, CONCAT(ROUND(gg.finalgrade / gg.rawgrademax * 100 ,0), '%') AS Percentage, CASE WHEN ROUND(gg.finalgrade / gg.rawgrademax * 100 ,0) < 100 
THEN 'In Progress'
WHEN ROUND(gg.finalgrade / gg.rawgrademax * 100 ,0) = 100 
THEN 'Completed'
WHEN ROUND(gg.finalgrade / gg.rawgrademax * 100 ,0) IS NULL AND SEC_TO_TIME(SUM(TIME_TO_SEC(msst.value))) is NULL
THEN 'Not Started'
ELSE 'In Progress'
END AS 'Completion' FROM mdl_user AS u JOIN mdl_scorm_scoes_track AS msst ON u.id = msst.userid JOIN mdl_scorm AS x ON x.id = msst.scormid JOIN mdl_course AS co ON co.id = x.course JOIN mdl_grade_grades AS gg ON u.id = gg.userid JOIN mdl_grade_items AS gi ON gi.id = gg.itemid JOIN mdl_course_categories AS cc ON cc.id = co.category WHERE msst.element = 'cmi.core.total_time' AND gi.itemname = x.name GROUP BY msst.id ORDER BY u.id, co.fullname");
$result = mysql_numrows($query);

//Initialize the 3 columns and the total
$column_member = "";
$column_fullname = "";
$column_name = "";
$column_time = "";
$column_percentage = "";

//For each row, add the field to the corresponding column

while($row = mysql_fetch_array($query))
{
    $member = $row["Member"];
    $fullname = $row["fullname"];
    $name = $row["name"];
    $time = $row["Time"];
    $percentage = $row["Percentage"];

    $column_main = $column_main.$main."\n";
    $column_member = $column_member.$member."\n";
    $column_fullname = $column_fullname.$fullname."\n";
    $column_name = $column_name.$name."\n";
    $column_time = $column_time.$time."\n";
    $column_percentage = $column_percentage.$percentage."\n";
}
mysql_close();

//Convert the Total Price to a number with (.) for thousands, and (,) for decimals.

//Create a new PDF file

$pdf=new PDF();
$pdf->AddPage();
//Fields Name position
$Y_Fields_Name_position = 20;
//Table position, under Fields Name
$Y_Table_Position = 26;

//First create each Field Name
//Gray color filling each Field Name box
$pdf->SetFillColor(232,232,232);
$pdf->SetFont('Arial','B',12);
$pdf->SetY(10);
$pdf->SetX(85);
$pdf->Cell(40,6,'Title',0,0,'C',0);
//Bold Font for Field Name
$pdf->SetFont('Arial','B',9);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(8);
$pdf->Cell(40,6,'Full Name',1,0,'C',1);
$pdf->SetX(48);
$pdf->Cell(55,6,'Course',1,0,'C',1);
$pdf->SetX(103);
$pdf->Cell(50,6,'Module',1,0,'C',1);
$pdf->SetX(153);
$pdf->Cell(25,6,'Time Spent',1,0,'C',1);
$pdf->SetX(178);
$pdf->Cell(25,6,'Percentage',1,0,'C',1);
$pdf->Ln();

//Now show the 3 columns
$pdf->SetFillColor(255,255,255);
$pdf->SetFont('Arial','',8);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(8);
$pdf->MultiCell(40,10,$column_member,1,'L',0,0,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(48);
$pdf->MultiCell(55,10,$column_fullname,1,'L',0,0,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(103);
$pdf->MultiCell(75,10,$column_name,1,'L',0,0,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(153);
$pdf->MultiCell(25,10,$column_time,1,'C',0,0,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(178);
$pdf->MultiCell(25,10,$column_percentage,1,'C',0,0,1);
$pdf->Ln();
$pdf->Ln();

//Create lines (boxes) for each ROW (Product)
//If you don't use the following code, you don't create the lines separating each row
$i = 0;
$pdf->SetY($Y_Table_Position);
while ($i < $result)
{
    $pdf->SetX(8);
    $pdf->MultiCell(195,10,'',1);
    $i = $i +1;
}

$pdf->Output();
$query=mysql\u query(“选择CONCAT(u.firstname,,,u.lastname)作为成员,co.fullname,x.name,SEC-TO-u-TIME(SUM(TIME-TO-SEC(msst.value)))作为时间,CONCAT(ROUND(gg.finalgrade/gg.rawgrademax*100,0),“%”作为百分比,在ROUND(gg.finalgrade/gg.rawgrademax*100,0)时以大小写<100
然后“进行中”
四舍五入时(gg.finalgrade/gg.rawgrademax*100,0)=100
然后“完成”
当舍入(gg.finalgrade/gg.rawgrademax*100,0)为空且秒到秒时间(总和(时间到秒(msst.value))为空时
然后“没有开始”
其他“进行中”
从mdl_用户以“完成”结束,因为你加入mdl_scoes_轨道作为u.id=msst.userid加入mdl_scorm AS x上的x.id=msst.scormid加入mdl_课程作为co上的co.id=x.课程加入mdl_等级作为u.id上的gg.userid加入mdl_等级作为gi上的gi.id=gg.itemid加入mdl_课程作为cc上的cc.id=co.类别,其中msst.element='cmi.core.total_time'和gi.itemname=x.name GROUP BY msst.id ORDER BY u.id,co.fullname”);
$result=mysql\u numrows($query);
//初始化3列和总计
$column_member=“”;
$column_fullname=“”;
$column_name=“”;
$column_time=“”;
$column_percentage=“”;
//对于每一行,将字段添加到相应的列中
while($row=mysql\u fetch\u array($query))
{
$member=$row[“member”];
$fullname=$row[“fullname”];
$name=$row[“name”];
$time=$row[“time”];
$percentage=$row[“percentage”];
$column\u main=$column\u main.$main.“\n”;
$column\u member=$column\u member.$member.“\n”;
$column\u fullname=$column\u fullname.$fullname.“\n”;
$column\u name=$column\u name.$name.“\n”;
$column\u time=$column\u time.$time.“\n”;
$column\u percentage=$column\u percentage.$percentage.“\n”;
}
mysql_close();
//将总价转换为一个数字,用(.)表示千,用(,)表示小数。
//创建一个新的PDF文件
$pdf=新pdf();
$pdf->AddPage();
//字段名称位置
$Y\字段\名称\位置=20;
//表位置,字段名称下
$Y_表_位置=26;
//首先创建每个字段名
//灰色填充每个字段名称框
$pdf->SetFillColor(232232);
$pdf->SetFont('Arial','B',12);
$pdf->SetY(10);
$pdf->SetX(85);
$pdf->Cell(40,6,'Title',0,0,'C',0);
//字段名的粗体字体
$pdf->SetFont('Arial','B',9);
$pdf->SetY($Y\u字段\名称\位置);
$pdf->SetX(8);
$pdf->Cell(40,6,'Full Name',1,0,'C',1);
$pdf->SetX(48);
$pdf->Cell(55,6,'Course',1,0,'C',1);
$pdf->SetX(103);
$pdf->Cell(50,6,'Module',1,0,'C',1);
$pdf->SetX(153);
$pdf->Cell(25,6,'Time-speed',1,0,'C',1);
$pdf->SetX(178);
$pdf->Cell(25,6,'Percentage',1,0,'C',1);
$pdf->Ln();
//现在显示3列
$pdf->SetFillColor(255255);
$pdf->SetFont('Arial','',8);
$pdf->SetY($Y\u Table\u Position);
$pdf->SetX(8);
$pdf->MultiCell(40,10,$column_成员,1,'L',0,0,1);
$pdf->SetY($Y\u Table\u Position);
$pdf->SetX(48);
$pdf->MultiCell(55,10,$column_fullname,1,'L',0,0,1);
$pdf->SetY($Y\u Table\u Position);
$pdf->SetX(103);
$pdf->MultiCell(75,10,$column_name,1,'L',0,0,1);
$pdf->SetY($Y\u Table\u Position);
$pdf->SetX(153);
$pdf->MultiCell(25,10,$column_time,1,'C',0,0,1);
$pdf->SetY($Y\u Table\u Position);
$pdf->SetX(178);
$pdf->MultiCell(25,10,$column_percentage,1,'C',0,0,1);
$pdf->Ln();
$pdf->Ln();
//为每行(产品)创建行(框)
//如果不使用以下代码,则不会创建分隔每行的行
$i=0;
$pdf->SetY($Y\u Table\u Position);
而($i<$result)
{
$pdf->SetX(8);
$pdf->MultiCell(195,10',1);
$i=$i+1;
}
$pdf->Output();
这可以很好地显示我需要的所有行,但是是否可以在新的pdf页面上显示每个特定用户的结果


谢谢,

我想你必须为用户创建不同的PDF,然后合并它们。我只是想我使用WKHTMLTOPDF,并且必须提供一种页面格式(例如A4)来拆分页面检查我的问题是我试图为用户创建一个动态报告,但我无法拆分查询以在单独的表中显示每个用户的结果或行,不一定是单独的pdf页面。