php/fpdf表格打印相同的记录[英] php/fpdf table printing the same records

本文是小编为大家收集整理的关于php/fpdf表格打印相同的记录的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我试图在PDF

中打印它

在此处输入图像说明

但是记录是相同的,它的奇怪是因为它们在我的数据库中不一样.

问题: 标准,等级和备注下的记录是相同的,但在我的数据库中,记录并不相同.

这是我到目前为止的代码:

$sql_criteria = mysql_query("SELECT DISTINCT criteria, percentage  FROM tb_equivalent WHERE instructor_id = '$inst_id' AND description = '$desc' AND subj_code = '$code' AND term = '$term'");
    $criteria = array();
    while($row = mysql_fetch_assoc($sql_criteria)){
        $criteria[] = $row['criteria'];
        $pdf->SetFont('Arial','',9);
        $pdf->Cell(35,5,$row['criteria'],1,'','C');
        $x = $pdf->GetX();
        $y = $pdf->GetY(); 
        $pdf->SetXY($x-35, $y+5); 
        $pdf->Cell(17.5,5,'Ave',1,'','C');
        $pdf->Cell(17.5,5,$row['percentage']."%",1,'','C');
        $pdf->SetXY($x, $y);
    }

    $pdf->Cell(35,10,'Grade',1,0,'C');
    $pdf->Cell(35,10,'Remark',1,0,'C');
    $pdf->SetFont('Arial','',9);
    $pdf->Ln();
    $sql = mysql_query("SELECT * FROM tb_equivalent INNER JOIN tb_student ON tb_equivalent.stud_id=tb_student.stud_id WHERE tb_equivalent.instructor_id = '$inst_id' AND tb_equivalent.description = '$desc' AND tb_equivalent.subj_code = '$code' GROUP BY tb_equivalent.stud_name ORDER BY stud_lname ASC");
    while($row = mysql_fetch_array($sql)){
        $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');

        for($x = 0; $x < count($criteria); $x++){
            $query_rec = mysql_query("SELECT * FROM tb_equivalent INNER JOIN tb_student ON tb_equivalent.stud_id=tb_student.stud_id WHERE tb_equivalent.instructor_id = '$inst_id' AND tb_equivalent.criteria = '".$criteria[$x]."' AND tb_equivalent.description = '$desc' AND tb_equivalent.subj_code = '$code' AND tb_equivalent.term = '$term' ORDER BY stud_lname ASC");
            $record = mysql_fetch_array($query_rec);
            $pdf->Cell(17.5,4,$record['average'],1,0,'C');
            $pdf->Cell(17.5,4,$record['equivalent'],1,0,'C');

        }
        $query_grade = mysql_query("SELECT grade, remark FROM tb_record_grade WHERE instructor_id = '$inst_id' AND description = '$desc' AND subj_code = '$code' AND term = '$term'");
        $row_grade = mysql_fetch_array($query_grade);
        $pdf->Cell(35,4,$row_grade['grade'],1,0,'C');
        $pdf->Cell(35,4,$row_grade['remark'],1,0,'C');
        $pdf->Ln();
    }

推荐答案

您错过了其他mysql提取的时循环.

$stud_id = $row['stud_id'];
for($x = 0; $x < count($criteria); $x++){
    $query_rec = mysql_query("
        SELECT * 
        FROM tb_equivalent 
        INNER JOIN tb_student ON tb_equivalent.stud_id = tb_student.stud_id 
        WHERE tb_equivalent.instructor_id = '$inst_id' AND tb_equivalent.criteria = '".$criteria[$x]."' 
          AND tb_equivalent.description = '$desc' AND tb_equivalent.subj_code = '$code' AND tb_equivalent.term = '$term'
          AND  tb_equivalent.stud_id = '$stud_id'
    ");
    while ($record = mysql_fetch_array($query_rec)) {
      $pdf->Cell(17.5,4,$record['average'],1,0,'C');
      $pdf->Cell(17.5,4,$record['equivalent'],1,0,'C');
    }

}
$query_grade = mysql_query("
  SELECT grade, remark 
  FROM tb_record_grade 
  WHERE instructor_id = '$inst_id' AND description = '$desc' AND subj_code = '$code' AND term = '$term'
");
while ($row_grade = mysql_fetch_array($query_grade)) {
  $pdf->Cell(35,4,$row_grade['grade'],1,0,'C');
  $pdf->Cell(35,4,$row_grade['remark'],1,0,'C');
}
$pdf->Ln();

本文地址:https://www.itbaoku.cn/post/2090943.html

问题描述

I am trying to print this in pdf

enter image description here

but the records are the same, its odd because they are not the same in my database.

Problem: The records under the criteria, grade and remark are the same but in my database, the are not the same.

this is my code so far:

$sql_criteria = mysql_query("SELECT DISTINCT criteria, percentage  FROM tb_equivalent WHERE instructor_id = '$inst_id' AND description = '$desc' AND subj_code = '$code' AND term = '$term'");
    $criteria = array();
    while($row = mysql_fetch_assoc($sql_criteria)){
        $criteria[] = $row['criteria'];
        $pdf->SetFont('Arial','',9);
        $pdf->Cell(35,5,$row['criteria'],1,'','C');
        $x = $pdf->GetX();
        $y = $pdf->GetY(); 
        $pdf->SetXY($x-35, $y+5); 
        $pdf->Cell(17.5,5,'Ave',1,'','C');
        $pdf->Cell(17.5,5,$row['percentage']."%",1,'','C');
        $pdf->SetXY($x, $y);
    }

    $pdf->Cell(35,10,'Grade',1,0,'C');
    $pdf->Cell(35,10,'Remark',1,0,'C');
    $pdf->SetFont('Arial','',9);
    $pdf->Ln();
    $sql = mysql_query("SELECT * FROM tb_equivalent INNER JOIN tb_student ON tb_equivalent.stud_id=tb_student.stud_id WHERE tb_equivalent.instructor_id = '$inst_id' AND tb_equivalent.description = '$desc' AND tb_equivalent.subj_code = '$code' GROUP BY tb_equivalent.stud_name ORDER BY stud_lname ASC");
    while($row = mysql_fetch_array($sql)){
        $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');

        for($x = 0; $x < count($criteria); $x++){
            $query_rec = mysql_query("SELECT * FROM tb_equivalent INNER JOIN tb_student ON tb_equivalent.stud_id=tb_student.stud_id WHERE tb_equivalent.instructor_id = '$inst_id' AND tb_equivalent.criteria = '".$criteria[$x]."' AND tb_equivalent.description = '$desc' AND tb_equivalent.subj_code = '$code' AND tb_equivalent.term = '$term' ORDER BY stud_lname ASC");
            $record = mysql_fetch_array($query_rec);
            $pdf->Cell(17.5,4,$record['average'],1,0,'C');
            $pdf->Cell(17.5,4,$record['equivalent'],1,0,'C');

        }
        $query_grade = mysql_query("SELECT grade, remark FROM tb_record_grade WHERE instructor_id = '$inst_id' AND description = '$desc' AND subj_code = '$code' AND term = '$term'");
        $row_grade = mysql_fetch_array($query_grade);
        $pdf->Cell(35,4,$row_grade['grade'],1,0,'C');
        $pdf->Cell(35,4,$row_grade['remark'],1,0,'C');
        $pdf->Ln();
    }

推荐答案

you missed the while loops for the other mysql fetches.

$stud_id = $row['stud_id'];
for($x = 0; $x < count($criteria); $x++){
    $query_rec = mysql_query("
        SELECT * 
        FROM tb_equivalent 
        INNER JOIN tb_student ON tb_equivalent.stud_id = tb_student.stud_id 
        WHERE tb_equivalent.instructor_id = '$inst_id' AND tb_equivalent.criteria = '".$criteria[$x]."' 
          AND tb_equivalent.description = '$desc' AND tb_equivalent.subj_code = '$code' AND tb_equivalent.term = '$term'
          AND  tb_equivalent.stud_id = '$stud_id'
    ");
    while ($record = mysql_fetch_array($query_rec)) {
      $pdf->Cell(17.5,4,$record['average'],1,0,'C');
      $pdf->Cell(17.5,4,$record['equivalent'],1,0,'C');
    }

}
$query_grade = mysql_query("
  SELECT grade, remark 
  FROM tb_record_grade 
  WHERE instructor_id = '$inst_id' AND description = '$desc' AND subj_code = '$code' AND term = '$term'
");
while ($row_grade = mysql_fetch_array($query_grade)) {
  $pdf->Cell(35,4,$row_grade['grade'],1,0,'C');
  $pdf->Cell(35,4,$row_grade['remark'],1,0,'C');
}
$pdf->Ln();