php
2013-05-06 3 views 0 likes 
0

보고서를 생성 할 때 null 값을 갖는 열을 숨기는 데 도움이 필요합니다. 보고서를 생성 할 때 NULL 열이 아닌 값만 표시됩니다.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"; 

IM 만이 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> 
+0

여기서 X는 쿼리에서 null이 아니거나 PHP에서 열에 대한 검사를 수행합니다. – Patashu

답변

0

PHP 쪽에서 NULL을 확인하는 것이 더 쉬울 것입니다. if (is_null($variable))

+0

왜 PHP로 더 쉽게 할 수 있습니까? –

+0

MySQL 쿼리가 빠르며 높은 확률이 없기 때문에 10-20 % 이상이 NULL이됩니다. 그렇다면 DB 디자인이 잘못되었습니다. –

관련 문제