gpt4 book ai didi

php - HTML/FPDF 表格

转载 作者:行者123 更新时间:2023-11-29 02:18:34 24 4
gpt4 key购买 nike

我正在努力将这份报告打印成 pdf:

goodReport

但我得到的只是这个:

badReport

在这份报告中,每个学生在Exam列中都有一条记录, Progress Report , Quiz , 和 Project .

示例数据:

enter image description here

这是我的部分代码:

while($row = mysql_fetch_assoc($sql_criteria)){
$criteria[] = $row['criteria'];
$pdf->SetFont('Arial','',9);
$pdf->Cell(35,5,$row['criteria'],1,'','C');
}
$pdf->Cell(35,5,'Grade',1,0,'C');
$pdf->Cell(35,5,'Remark',1,0,'C');
$pdf->SetFont('Arial','',9);
$pdf->Ln();
while($row = mysql_fetch_array($sql)){
$criteria_array = implode(" ", $criteria);
$query_rec = mysql_query("SELECT equivalent FROM tb_student_record WHERE instructor_id = '$inst_id' AND criteria = '$criteria_array' AND description = '$desc' AND subj_code = '$code' AND term = '$term'");
$record = mysql_fetch_array($query_rec);
$name = $row['stud_name'];
$course = $row['course_and_year'];
$pdf->SetFont('Arial','',9);
$pdf->Cell(1);
$pdf->Cell(40,4,$name,1);
$pdf->Cell(20,4,$course,1,0,'C');
$pdf->Cell(5,4,$record['equivalent'],1,0,'C');
$pdf->Ln();
}

因此,如果它有任何问题或问题...请指出来...任何帮助将不胜感激,提前致谢

最佳答案

  • 您只尝试在代码中每行显示三列
  • 我们必须遍历所有标准以显示要显示的必要数据

假设 $criteria 是一个数组(删除 implode() 部分):

$criteria = array("Exam", "Progress Report", "Quiz", "Project");

然后运行它们并将其绑定(bind)到您的查询:

$pdf->SetFont('Arial','',9); /* SET FONT TO ARIAL WITH FONT SIZE OF 9 */

while($row = mysql_fetch_array($sql)){ /* RUN THROUGH EACH STUDENT */

$pdf->Cell(1);
$pdf->Cell(40,4,$row['stud_name'],1); /* DISPLAY THE STUDENT'S NAME */
$pdf->Cell(20,4,$row['course_and_year'],1,0,'C'); /* DISPLAY THE COURSE AND YEAR */

for($x = 0; $x < count($criteria); $x++){ /* RUN ALL FOUR CRITERIAS */

$query_rec = mysql_query("SELECT equivalent FROM tb_student_record WHERE instructor_id = '$inst_id' AND criteria = '".$criteria[$x]."' AND description = '$desc' AND subj_code = '$code' AND term = '$term'");
$record = mysql_fetch_array($query_rec);
$pdf->Cell(5,4,$record['equivalent'],1,0,'C'); /* DISPLAY THE SCORE FOR THE EQUIVALENT CRITERIA */

} /* END OF FOR LOOP */

$pdf->Ln(); /* NEW LINE */

} /* END OF WHILE LOOP; RUNNING THROUGH ALL THE STUDENTS */

顺便说一下,如果你有时间,可以考虑使用 mysqli_*为您的项目,而不是使用 deprecated mysql_*.

关于php - HTML/FPDF 表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35496468/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com