在fpdf中操作和定位细胞

时间:2016-02-20 00:01:15

标签: php fpdf

我正在打印此表

enter image description here

但我拥有的是这个

enter image description here

Ave和百分比应低于(考试,实验室,测验和背诵)标准

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

$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');
    $pdf->Cell(17.5,5,'Ave',1,'','C');
    $pdf->Cell(17.5,5,$row['percentage']."%",1,'','C');
}

$pdf->Cell(35,10,'Grade',1,0,'C');
$pdf->Cell(35,10,'Remark',1,0,'C');

对我的问题的任何帮助将不胜感激,并且请...提前感谢我的代码中指出错误

1 个答案:

答案 0 :(得分:0)

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(); // get current x pos
    $y = $pdf->GetY(); // get current y pos
    $pdf->SetXY($x-35, $y+5); // move pointer back to start of and under criteria cell
    $pdf->Cell(17.5,5,'Ave',1,'','C');
    $pdf->Cell(17.5,5,$row['percentage']."%",1,'','C');
    $pdf->SetXY($x, $y); // set pointer back to end of criteria cell
}