Skip to content
Advertisement

php – fpdf select case $row

I am using FPDF and have the following code:

// Data
foreach($data as $row)
{ 
$this->SetFont('Arial','',12);
$this->Cell($w[0],6,$row[0],'','','C'); //Year
$this->Cell($w[1],6,$row[1],'','','R'); //Details
$this->Cell($w[14],6,number_format($row[14],0,",","."),'',0,'R'); //Totals
$this->Ln();
}

I would like to have select case and have something like that:

for i=1 to 7
  select case $row
    case 1
    case 2
    ..
  end select
loop

I would like to have to each row of data different style, and since I know that the rows are repeating every 7 rows, I can have a loop and make selection.

Advertisement

Answer

This should provide you the details to move forward. It wasn’t clear from what you provided what type of styling you were going to do for each of the 7 row styles so I simply put in a comment for each of the possibilities.

$stylecount = 1;
// Data
foreach($data as $row) {
   switch ($stylecount) {

       case 1:
           // set style 1 here
       break;

       case 2:
           // set style 2 here
       break;

       case 3:
           // set style 3 here
       break;

       case 4:
           // set style 4 here
       break;

       case 5:
           // set style 5 here
       break;

       case 6:
           // set style 6 here
       break;

       case 7:
           // set style 7 here
           $stylecount = 0;  // reset count
       break;
   }  // end of switch

   $this->SetFont('Arial','',12);
   $this->Cell($w[0],6,$row[0],'','','C'); //Year
   $this->Cell($w[1],6,$row[1],'','','R'); //Details
   $this->Cell($w[14],6,number_format($row[14],0,",","."),'',0,'R'); //Totals
   $this->Ln();
   $stylecount++;  // bump stype count by 1
}
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement