如何在tcpdf上显示独特的价值?

时间:2016-09-08 02:13:57

标签: php tcpdf

参考 - http://i.stack.imgur.com/oAIbz.png

foreach($data as $k=>$v){
//print_r($v);
exit;    
if ($yr != $v['year']) {
$pdf->SetFont('helvetica', 'B',9);
$pdf->Cell(25,4, 'Payment Year :',0,0,'L', false,'',0,false,'T','M');
$pdf->SetFont('helvetica', '',9);
$pdf->Cell(10,4, $v['year'],0,1,'L', false,'',0,false,'T','M');

//header
$pdf->SetFont('helvetica', 'B',9);
$pdf->Cell(67,4, 'Student',1,0,'C', false,'',0,false,'T','M');
$pdf->Cell(30,4, $v['year'].' Class',1,0,'C', false,'',0,false,'T','M');
$pdf->Cell(47,4, 'Fee',1,0,'C', false,'',0,false,'T','M');
$pdf->Cell(20,4, 'Amount',1,0,'C', false,'',0,false,'T','M');
$pdf->Cell(20,4, 'Total',1,1,'C', false,'',0,false,'T','M');
$pdf->SetFont('helvetica', '',9);       

//$total1 = $total1 + $v['amount'];
$total1 = 0;
 $yr = $v['year'];    
}  

$pdf->MultiCell(67, 4,  $v['student_name'], 1, 'L', 0, 0, '', '', true, 0, false, true, 8, 'T', false);
$pdf->MultiCell(30, 4,  $v['class_english_name'], 1, 'L', 0, 0, '', '', true, 0, false, true, 8, 'T', false); 
$pdf->MultiCell(47, 4,  $v['fee_group_desc'], 1, 'L', 0, 0, '', '', true, 0, false, true, 8, 'T', false);
$pdf->MultiCell(20, 4,  '*'.number_format($v['amount'],2), 1, 'C', 0, 0, '', '', true, 0, false, true, 8, 'T', false);  
$total1 = $total1 + $v['amount'];
$total2 = $total2 + $v['amount'];
$pdf->MultiCell(20, 4,  number_format($total1,2), 1, 'C', 0, 1, '', '', true, 0, false, true, 8, 'T', false);

`

1 个答案:

答案 0 :(得分:0)

我想你的某种循环?你需要存储你已经使用过该名称的事实,并且对于其余的循环检查你是否使用了这个名称来确定你是否需要再次显示它

在循环之外

$name_used=FALSE;//default to false

然后在你的循环中

if(!$name_used){

$pdf->MultiCell(67, 4,  $v['student_name'], 1, 'L', 0, 0, '', '', true, 0, false, true, 8, 'T', false);
$name_used=TRUE;//after first time through loop make this true, so name not used again    
}else{
//maybe noting, maybe a blank cell
}