2012-09-20 4 views
0

Im использует mPDF для создания PDF-файлов и отправки отчетов клиентам.Foreach в строке таблицы

Я использую этот Еогеасп, чтобы заполнить мою строку таблицы

$report_nr = $this->input->post('report_nr'); 
     $date = $this->input->post('date'); 
     $owner = $this->input->post('owner'); 
     $ar1 = $this->input->post('column01'); 
     $ar2 = $this->input->post('column02'); 
     $ar3 = $this->input->post('column03'); 
     $ar4 = $this->input->post('column04'); 
     $ar5 = $this->input->post('column05'); 
     $ar6 = $this->input->post('column06'); 
     $ar7 = $this->input->post('column07'); 
     $ar8 = $this->input->post('column08'); 
     $ar9 = $this->input->post('column09'); 
     $ar10 = $this->input->post('column10'); 

     include('../mpdf.php'); 
     $mpdf = new mPDF('', // mode - default '' 
      'A4', // format - A4, for example, default '' 
      0,  // font size - default 0 
      '', // default font family 
      15, // margin_left 
      15, // margin right 
      16,  // margin top 
      16, // margin bottom 
      9,  // margin header 
      9,  // margin footer 
      'P'); // L - landscape, P - portrait 
     //$this->customer_report(); 
     $n=0; //start counting at 0, like array counters do. 
     foreach ($ar2 as $thing) { //for each value of $ar2 
     $bigar[$n][2] = $thing; //set $bigarray at $n at 1 to that part 
     $n++; //add one to $n, continue 
     } 
     $n=0; //repeat for array 3 
     foreach ($ar3 as $thing) { 
     $bigar[$n][3] = $thing; //now use the 2 value of the array 
     $n++; 
     } 
     $n=0; //repeat for array 4 
     foreach ($ar5 as $thing) { 
     $bigar[$n][5] = $thing; //now use the 2 value of the array 
     $n++; 
     } 
     $n=0; //start counting at 0, like array counters do. 
     foreach ($ar6 as $thing) { //for each value of $ar2 
     $bigar[$n][6] = $thing; //set $bigarray at $n at 1 to that part 
     $n++; //add one to $n, continue 
     } 
     $n=0; //repeat for array 3 
     foreach ($ar8 as $thing) { 
     $bigar[$n][8] = $thing; //now use the 2 value of the array 
     $n++; 
     } 
     $n=0; //repeat for array 4 
     foreach ($ar9 as $thing) { 
     $bigar[$n][9] = $thing; //now use the 2 value of the array 
     $n++; 
     } 
     $n=0; //repeat for array 1 
     foreach ($ar1 as $thing) { 
     $bigar[$n][1] = $thing; //now use the 2 value of the array 
     $n++; 
     } 
     $this->mpdf->WriteHTML("<table border='1'>"); 
     $this->mpdf->WriteHTML('<thead><tr><th class="span1">Relatório Nº :</th><th>&nbsp;'.$report_nr.'&nbsp;</th><th>Data :</th><th>&nbsp;'.$date.'&nbsp;</th><th>Cliente :</th><th colspan="5">&nbsp;'.$owner.'&nbsp;</th></tr></thead>'); 
     $this->mpdf->WriteHTML("<tbody>"); 
     $this->mpdf->WriteHTML("<tr>"); 
     foreach ($bigar as $part) { //go through each chunk of the array 
      if($i%10 == 0 && $i != 0) { 
      $this->mpdf->WriteHTML("</tr>"); 
      $this->mpdf->WriteHTML("<tr>"); 
      } 
     $this->mpdf->WriteHTML("<td>"); 
     $this->mpdf->WriteHTML("<table><tbody><tr><td>&nbsp;".($part[2]+$part[3])."&nbsp;</td><td>&nbsp;".($part[5]+$part[6])."&nbsp;</td><td>&nbsp;".($part[8]+$part[9]).'&nbsp;</td></tr><tr><td colspan="3">&nbsp;'.$part[1]."&nbsp;</td></tr></tbody></table>"); 
     $this->mpdf->WriteHTML("</td>"); //now, like above, that part has [1], and [2] 
     $i++; 
     } 
     $this->mpdf->WriteHTML("</tr>"); 
     $this->mpdf->WriteHTML("</tbody></table>"); 

Как вы можете видеть на последнем ряде ... когда я достигну 10 клеток, это создать еще одну строку. Теперь мне нужна последняя строка, чтобы добраться до 10 ячеек, даже если нет содержимого на массивах, в противном случае она не создаст полную строку, что делает мой стол бесполезным в конце ...

Вот принт-экран Ф:

PrintScreen

Надежда Я ясно.

Спасибо всем

ответ

0

Найден способ сделать это, и я хочу поделиться с и.

} 
    $this->mpdf->WriteHTML('<table border="1">'); 
    $this->mpdf->WriteHTML('<thead><tr><th>Relatório Nº :</th><th>&nbsp;'.$report_nr.'&nbsp;</th><th>Data :</th><th>&nbsp;'.$date.'&nbsp;</th><th>Cliente :</th><th colspan="5">&nbsp;'.$owner.'&nbsp;</th></tr></thead>'); 
    $this->mpdf->WriteHTML("<tbody>"); 
    $this->mpdf->WriteHTML("<tr>"); 
    foreach ($bigar as $part) { //go through each chunk of the array 
     if($i%10 == 0 && $i != 0) { 
     $this->mpdf->WriteHTML('</tr>'); 
     $this->mpdf->WriteHTML('<tr>'); 
     } 

    $this->mpdf->WriteHTML("<td>"); 
    $this->mpdf->WriteHTML("<table border='1'><tbody><tr><td>&nbsp;".($part[2]+$part[3])."&nbsp;</td><td>&nbsp;".($part[5]+$part[6])."&nbsp;</td><td>&nbsp;".($part[8]+$part[9]).'&nbsp;</td></tr><tr><td colspan="3">&nbsp;'.$part[1]."&nbsp;</td></tr></tbody></table>"); 
    $this->mpdf->WriteHTML("</td>"); //now, like above, that part has [1], and [2] 


    $i++; 

    } 
    $this->mpdf->WriteHTML('<td colspan="'.(10-($i%10)).'"></td></tr>'); 
    $this->mpdf->WriteHTML("</tbody></table>"); 
    //$bigar_removed = ereg_replace("0", "", $bigar); 
    //$this->mpdf->WriteHTML("".$bigar_removed.""); 
     $this->mpdf->WriteHTML("<pagebreak>"); 

     $this->mpdf->Output(); 
     exit; 
    } 

Уловка была найдена способ узнать, какой номер ячейки был в последний раз создан в строке.

$this->mpdf->WriteHTML('<td colspan="'.(10-($i%10)).'"></td></tr>'); 

Таким образом, я просто вычитают число от 10, который оставил меня с номером для использования с coldspan, имеющий ряд полной.

Надеюсь, это поможет некоторым из вас!

Благодарю вас всех

+1

Не забудьте принять это как ответ. – stealthyninja

Смежные вопросы