繁体   English   中英

如何隐藏具有NULL行值的列

[英]how to hide a column which has NULL row value

在生成报告时需要帮助隐藏具有空值的列,我希望这样,以便在生成报告时仅显示非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 = '&nbsp';
            $prCat2 = $category_1;
            $prCat3 = $category_2;
            $prev2 = $category_1;
            $prev3 = $category_2;
        }
        elseif ($category_2 != $prev3) {
            $prCat1 = '&nbsp';
            $prCat2 = '&nbsp;';
            $prCat3 = $category_2;
            $prev3 = $category_2;
        }
        else $prCat1 = $prCat2 = $prCat3 = '&nbsp;';
        $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>

比较容易的是在PHP端检查NULL。 使用if (is_null($variable))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM