2012-07-20 42 views
0

好的,儘可能在這裏儘可能清楚。我正在嘗試生成一個包含顯示產品信息的各種字段的PDF文檔。從本質上講,產生PDF的腳本將確定是否已啓動產品更改,如果有,則會創建PDF。fpdf想要更改依賴於if/else語句的數組的SetFillColor

我現在想要做的是突出顯示與這些更改字段。要檢查是否有變化,我使用下列變量(其中大約有三十)數組在PDF文件中的產品輸出的

$cone 
$ctwo..... etc 

一個例子是:

$leftHeadArray[0]['leftText'] = 'ID'; 
    $leftHeadArray[0]['rightText'] = $ID; 


    $leftHeadArray[1]['leftText'] = 'start'; 
    $leftHeadArray[1]['rightText'] = date("d/m/Y", $Start); 


    $leftHeadArray[2]['leftText'] = 'End'; 
    $leftHeadArray[2]['rightText'] = date("d/m/Y", $End); 

的然後格式和細胞initated低於這個在:

$maxheader = max(array_keys($leftHeadArray), array_keys($midHeadArray), array_keys($rightHeadArray)); 

    for ($i = 0; $i <= max($maxheader); $i++) 
    { 
     if (isset($leftHeadArray[$i])) 
     { 
      $pdf->SetFont('helvetica', 'B', 6); 
      $pdf->SetFillColor(128, 0, 0); 
      $pdf->SetTextColor(255, 255, 255); 

      $pdf->Cell(40, 5, $leftHeadArray[$i]['leftText'], $border, 0, 'L', 1); 

      $pdf->SetFont('helvetica', 'N', 6); 
      if ($ctwentytwo == 0 && $leftHeadArray[1]['rightText'] || $ctwentytwo == 0 && $leftHeadArray[4]['rightText']){ 
      $pdf->SetFillColor(255, 255, 255); 
      $pdf->SetTextColor(0, 0, 0); 
      }else{ 
      $pdf->SetFillColor(0, 0, 0); 
      $pdf->SetTextColor(255, 255, 255); 
      } 

     $pdf->Cell(30, 5, $leftHeadArray[$i]['rightText'], $border, 0, 'L', 1); 
     $pdf->Cell(20, 5, '', 0, 0, 'L', 0); 
    } 

事情我已經試過不已:

  1. 包裹如果inidividual單元陣列

    周圍else語句(例如$ leftHeadArray [0] ['leftText'] ='ID'; $ leftHeadArray [0] [ 'rightText'] = $ ID)

    並試圖過乘坐組填充顏色內有

  2. 把如果else語句內是否isset部

事情我掙扎:

  • 連接$錐至$ leftheadarray
  • 當啓動更改時只更改一個單元格

我希望這是簡潔的!

// ------------------------------分辨

變量總是假設爲這樣需要0如果$ cone == 1,則返回聲明,並返回到左頭數組,如下所示:希望這有助於!

if (isset($leftHeadArray[$i])) 
     { 
      $pdf->SetFont('helvetica', 'B', 6); 
      $pdf->SetFillColor(128, 0, 0); 
      $pdf->SetTextColor(255, 255, 255); 

      $pdf->Cell(40, 5, $leftHeadArray[$i]['leftText'], $border, 0, 'L', 1); 

      $pdf->SetFont('helvetica', 'N', 6); 

      $pdf->SetFillColor(255, 255, 255); 
      $pdf->SetTextColor(128, 0, 0); 


      if (($ctwentytwo == 1) && ($leftHeadArray[$i]['leftText'] == "Promotion Start Date") 
      || ($cone == 1) && ($leftHeadArray[$i]['leftText'] == "Promotion ID") 
      || ($ctwo == 1) && ($leftHeadArray[$i]['leftText'] == "Promotion Type"))#|| $ctwentytwo == 0 && $leftHeadArray[1]['rightText'] 
      { 
       $pdf->SetFillColor(0, 0, 0); 
       $pdf->SetTextColor(255, 255, 255); 
      } 

      $pdf->Cell(30, 5, $leftHeadArray[$i]['rightText'], $border, 0, 'L', 1); 
      $pdf->Cell(20, 5, '', 0, 0, 'L', 0); 
     } 

回答

1
if (isset($leftHeadArray[$i])) 
     { 
      $pdf->SetFont('helvetica', 'B', 6); 
      $pdf->SetFillColor(128, 0, 0); 
      $pdf->SetTextColor(255, 255, 255); 

      $pdf->Cell(40, 5, $leftHeadArray[$i]['leftText'], $border, 0, 'L', 1); 

      $pdf->SetFont('helvetica', 'N', 6); 

      $pdf->SetFillColor(255, 255, 255); 
      $pdf->SetTextColor(128, 0, 0); 


      if (($ctwentytwo == 1) && ($leftHeadArray[$i]['leftText'] == "Promotion Start Date") 
      || ($cone == 1) && ($leftHeadArray[$i]['leftText'] == "Promotion ID") 
      || ($ctwo == 1) && ($leftHeadArray[$i]['leftText'] == "Promotion Type"))#|| $ctwentytwo == 0 && $leftHeadArray[1]['rightText'] 
      { 
       $pdf->SetFillColor(0, 0, 0); 
       $pdf->SetTextColor(255, 255, 255); 
      } 

      $pdf->Cell(30, 5, $leftHeadArray[$i]['rightText'], $border, 0, 'L', 1); 
      $pdf->Cell(20, 5, '', 0, 0, 'L', 0); 
     } 
+0

這是供將來參考答案 – PHPDev76 2012-08-14 22:57:47