在生成报告时需要帮助隐藏具有空值的列,我希望这样当我生成报告时,只会显示那些不是 NULL 的列
sql代码:
$sql ="SELECT trouble_type_priority as `Severity`
, category_1
, category_2
, SUM(IF(status='Resolved', 1, NULL)) as `Resolved`
, SUM(IF(status='Re-assigned', 1, NULL)) as `Re-assigned`
, SUM(IF(status='Closed', 1, NULL)) as `Closed`
, SUM(IF(status='Suspended', 1, NULL)) as `Suspended`
, COUNT(status) as `Total`
FROM tbl_main
WHERE resolved_date = '$dates'
GROUP BY Severity, category_1, category_2";
条件和输出:
$output =
"<tr>
<th colspan='3' align='center'>Ticket Bucket</th>
<th colspan='4' align='center'>Status</th>
<th width='auto' align='center' rowspan='2'>Total Tickets</th>
</tr>
<tr>
<th width='auto' align='center'>Severity</th>
<th width='auto' align='center'>Category 2</th>
<th width='auto' align='center'>Category 3</th>
<th width='auto' align='center'>Resolved</th>
<th width='auto' align='center'>Re-assigned</th>
<th width='auto' align='center'>Closed</th>
<th width='auto' align='center'>Suspended</th>
</tr>\n";
$prev1 = $prev2 = $prev3 = '';
$totResolved = $totReassigned = $totClosed = $totSuspended = $totAll = 0;
while (list($trouble_type_priority,$category_1,$category_2, $resolved, $reassigned,
$closed, $suspended, $total) = mysql_fetch_row($myData)) {
if ($trouble_type_priority != $prev1) {
$prCat1 = $trouble_type_priority;
$prCat2 = $category_1;
$prCat3 = $category_2;
$prev1 = $trouble_type_priority;
$prev2 = $category_1;
$prev3 = $category_2;
}
elseif ($category_1 != $prev2) {
$prCat1 = ' ';
$prCat2 = $category_1;
$prCat3 = $category_2;
$prev2 = $category_1;
$prev3 = $category_2;
}
elseif ($category_2 != $prev3) {
$prCat1 = ' ';
$prCat2 = ' ';
$prCat3 = $category_2;
$prev3 = $category_2;
}
else $prCat1 = $prCat2 = $prCat3 = ' ';
$output .= "<tr><td align='center'>$prCat1</td><td align='center'>$prCat2</td><td>$prCat3</td>
<td align='center'>$resolved</td><td align='center'>$reassigned</td><td align='center'>$closed</td><td align='center'>$suspended</td><td align='center'>$total</td></tr>\n";
$totResolved += $resolved;
$totReassigned += $reassigned;
$totClosed += $closed;
$totSuspended += $suspended;
$totAll += $total;
}
$output .= "<tr><th colspan='3' align='center'>Total Tickets</th><td align='center'>$totResolved</td><td align='center'>$totReassigned</td>
<td align='center'>$totClosed</td><td align='center'>$totSuspended</td><td align='center'>$totAll</td></tr>\n";
我只指这 4 列:
<th width='auto' align='center'>Resolved</th>
<th width='auto' align='center'>Re-assigned</th>
<th width='auto' align='center'>Closed</th>
<th width='auto' align='center'>Suspended</th>