0
嘿家伙我只是想让这个愚蠢的事情工作,我可以从那里调整, 我开始一个数组,它将最有可能通过$ _POST ,带有多个查询和数据阵列的PHP PDF写作
$cleanArray = array(array('type'=>'berries', 'numb'=>'5555'),
array('type'=>'melons', 'numb'=>'686'));
我再声明一些数据阵列,将提供结构(如果有一个更好的方式来做到这一点特定的步骤,让我知道!),这是三种类型,有总共六个。查询是唯一查询,每个类型需要返回正确的信息,而尺寸是字段大小是用于该项目在pdf中。
$dataShape = array(
'berries' => array( 'sizes' => array(0 => 25, 1 => 20, 3 => 10, 4 => 15, 5 => 10, 6 => 20, 7 => 20, 8 => 10, 9 => 15, 10 => 10, 11 => 15, 12 => 10, 13 => 10, 14 => 10, 15 => 10, 16 => 10, 17 => 10, 18 => 10, 19 => 200),
'query' => array('shipper, po, commodity as comm, count, size, label, variety, pack_date AS date, grower_lot AS lot, CONCAT(color1, "-", color2) AS color, CONCAT(sizing1, "-", sizing2, "/", "sizing3", "-", sizing4) AS size, CONCAT(firmness1, "-", firmness2) AS firmness, CONCAT(scars_count1, "-", scars_count2) AS scars_count, CONCAT(bruise_count2, "-", bruise_count2) AS bruise_count, CONCAT(decay_count1, "-", decay_count2) AS green, CONCAT(sugar_brix1, "-", sugar_brix2) brix, rating, comments')),
'citrus' => array( 'sizes' => array(0 => 25, 1 => 20, 3 => 10, 4 => 15, 5 => 10, 6 => 20, 7 => 20, 8 => 10, 9 => 15, 10 => 10, 11 => 15, 12 => 10, 13 => 10, 14 => 10, 15 => 10, 16 => 10, 17 => 10, 18 => 10, 19 => 200),
'query' => array('shipper, po, commodity as comm, count, size, label, variety, pack_date AS date, grower_lot AS lot, CONCAT(color1, "-", color2) AS color, CONCAT(texture1, "-", texture2) AS texture, CONCAT(puff1, "-", puff2) AS puff, CONCAT(scar1, "-", scar2) AS scars, CONCAT(solidity1, "-", solidity2) AS solidity, CONCAT(green1, "-", green2) AS green, CONCAT(sugar_brix1, "-", sugar_brix2) brix, rating, comments')),
'melons' => array( 'sizes' => array(0 => 25, 1 => 20, 3 => 10, 4 => 15, 5 => 10, 6 => 20, 7 => 20, 8 => 10, 9 => 15, 10 => 10, 11 => 15, 12 => 10, 13 => 10, 14 => 10, 15 => 10, 16 => 10, 17 => 10, 18 => 200),
'query' => array('shipper, po, commodity as comm, count, size, label, variety, pack_date AS date, grower_lot AS lot, CONCAT(color1, "-", color2) AS color, CONCAT(ground_color1, "-", ground_color2) AS ground_color, CONCAT(texture1, "-", texture2) AS texture, CONCAT(scar1, "-", scar2) AS scars, CONCAT(solidity1, "-", solidity2) AS solidity, CONCAT(cut1, "-", cut2) AS cut, CONCAT(sugar_brix1, "-", sugar_brix2) brix, rating, comments')),
);
我然后尝试基于所述类型查询,和类型的结构,这将命名每个阵列type
名称,并打开每个部分成子阵列。 You can see it here.
foreach($cleanArray as $key=>$val) { echo $key;
$result[$cleanArray[$key]['type']]
= $dbc->fetch_array("SELECT ".implode(',',$dataShape[ $cleanArray[$key]['type'] ]['query'])." FROM `"
.$cleanArray[$key]['type']."` WHERE (status = '0' OR status = '1') AND `report_key` = "
.$cleanArray[$key]['numb']);
}
然后我尝试添加页面,并迭代东西,这是行不通的。它应该一次使用这些键来获取列名,然后遍历键值直到用完。如果值小于十二行(总共24行,因为注释占用自己的行)迭代空白行直到有12行存在。
foreach($result as $fruitType=>$fruitTypeArray) {
$nameKeys = array_keys($fruitTypeArray[0]);
$i=0; $pdf->AddPage('L');
foreach($dataShape[$fruitType]['sizes'] as $dataShapevalue) {
$pdf->Cell($dataShapevalue6,ucwords(str_replace('_',' ',$nameKeys[$i++])),1,0,'L',1);
}
// go to next row
$y_axis = $y_axis + $row_height;
foreach($dataShape[$fruitType]['sizes'] as $dataShapeValue) {
foreach($fruitTypeArray as $queryName=>$queryValue) {
if(!$queryName=='comments') {
$pdf->Cell($dataShapeValue,6,$queryValue,1,0,'L',1);
} else {
// go to next row
$y_axis = $y_axis + $row_height;
$pdf->Cell($dataShapeValue,6,ucwords(str_replace('_',' ',$nameKeys[$i++])),1,0,'L',1);
// go to next row
$y_axis = $y_axis + $row_height;
}
}