表行上的Foreach
Im使用mPDF生成PDF并向客户发送报告 我用这个foreach来填充我的表行表行上的Foreach,foreach,codeigniter-2,Foreach,Codeigniter 2,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')
$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> '.$report_nr.' </th><th>Data :</th><th> '.$date.' </th><th>Cliente :</th><th colspan="5"> '.$owner.' </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> ".($part[2]+$part[3])." </td><td> ".($part[5]+$part[6])." </td><td> ".($part[8]+$part[9]).' </td></tr><tr><td colspan="3"> '.$part[1]." </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>");
$report\u nr=$this->input->post('report\u 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');
包括('../mpdf.php');
$mpdf=新的mpdf(“”,//模式-默认值“”
“A4',//格式为-A4,例如,默认值”
0,//字体大小-默认值为0
'',//默认字体系列
15,//左边空白处
15、//右边距
16,//页边距顶部
16,//页边距底部
9,//页边距页眉
9,//页边距页脚
‘P’;//L-横向,P-纵向
//$this->customer_report();
$n=0//像数组计数器一样,从0开始计数。
foreach($ar2作为$thing){//每值$ar2
$bigar[$n][2]=$thing;//在该部分的1处将$bigarray设置为$n
$n++;//将一个添加到$n,继续
}
$n=0//对数组3重复此操作
foreach($ar3作为$thing){
$bigar[$n][3]=$thing;//现在使用数组的2值
$n++;
}
$n=0//对数组4重复此操作
foreach($ar5作为$thing){
$bigar[$n][5]=$thing;//现在使用数组的2值
$n++;
}
$n=0//像数组计数器一样,从0开始计数。
foreach($ar6作为$thing){//每值$ar2
$bigar[$n][6]=$thing;//在该部分的1处将$bigarray设置为$n
$n++;//将一个添加到$n,继续
}
$n=0//对数组3重复此操作
foreach($ar8作为$thing){
$bigar[$n][8]=$thing;//现在使用数组的2值
$n++;
}
$n=0//对数组4重复此操作
foreach($ar9作为$thing){
$bigar[$n][9]=$thing;//现在使用数组的2值
$n++;
}
$n=0//对数组1重复此操作
foreach($ar1作为$thing){
$bigar[$n][1]=$thing;//现在使用数组的2值
$n++;
}
$this->mpdf->WriteHTML(“”);
$this->mpdf->WriteHTML('Relatório N:'.$report_nr.'Data:'.$date.'Cliente:'.$owner.');
$this->mpdf->WriteHTML(“”);
$this->mpdf->WriteHTML(“”);
foreach($bigaras$part){//遍历数组的每个块
如果($i%10==0&&$i!=0){
$this->mpdf->WriteHTML(“”);
$this->mpdf->WriteHTML(“”);
}
$this->mpdf->WriteHTML(“”);
$this->mpdf->WriteHTML(“($part[2]+$part[3])。”($part[5]+$part[6])。($part[8]+$part[9])。$part[1]);
$this->mpdf->WriteHTML(“”;//现在,像上面一样,该部分有[1]和[2]
$i++;
}
$this->mpdf->WriteHTML(“”);
$this->mpdf->WriteHTML(“”);
正如你在最后一行看到的…当我达到10个单元格时,它会创建另一行。
现在,即使数组中没有内容,我也需要最后一行到达10个单元格,否则它将无法创建完整的行,这将使我的表最终变得一团糟
以下是pdf的打印屏幕:
希望我说清楚
谢谢大家找到了这样做的方法,我想与大家分享
}
$this->mpdf->WriteHTML('<table border="1">');
$this->mpdf->WriteHTML('<thead><tr><th>Relatório Nº :</th><th> '.$report_nr.' </th><th>Data :</th><th> '.$date.' </th><th>Cliente :</th><th colspan="5"> '.$owner.' </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> ".($part[2]+$part[3])." </td><td> ".($part[5]+$part[6])." </td><td> ".($part[8]+$part[9]).' </td></tr><tr><td colspan="3"> '.$part[1]." </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(“”);
$this->mpdf->WriteHTML('Relatório N:'.$report_nr.'Data:'.$date.'Cliente:'.$owner.');
$this->mpdf->WriteHTML(“”);
$this->mpdf->WriteHTML(“”);
foreach($bigaras$part){//遍历数组的每个块
如果($i%10==0&&$i!=0){
$this->mpdf->WriteHTML(“”);
$this->mpdf->WriteHTML(“”);
}
$this->mpdf->WriteHTML(“”);
$this->mpdf->WriteHTML(“($part[2]+$part[3])。”($part[5]+$part[6])。($part[8]+$part[9])。$part[1]);
$this->mpdf->WriteHTML(“”;//现在,像上面一样,该部分有[1]和[2]
$i++;
}
$this->mpdf->WriteHTML(“”);
$this->mpdf->WriteHTML(“”);
//$bigar_removed=ereg_replace(“0”,”,$bigar);
//$this->mpdf->WriteHTML(“$bigar_已删除”);
$this->mpdf->WriteHTML(“”);
$this->mpdf->Output();
出口
}
诀窍是找到一种方法来知道行中最后创建的单元格编号
$this->mpdf->WriteHTML('<td colspan="'.(10-($i%10)).'"></td></tr>');
$this->mpdf->WriteHTML(“”);
这样,我就从10中减去了这个数字,剩下的数字将与coldspan一起使用,这就完成了行
希望它能帮助你们中的一些人
谢谢大家