我正在使用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();
这可以很好地显示我需要的所有行,但是每个特定用户的结果是否可以显示在新的pdf页面上?
谢谢,