2016-07-25 94 views
0

我有一個PHP代碼,用JSON查詢加載表上的記錄,循環直到讀取所有MySQL查詢結果。錶行背景顏色跳過行

我想添加表格行背景顏色。但它總是隻影響其他行。

我對PHP和Java相當陌生。我只通過在網絡上進行嘗試和研究來學習,並沒有任何正式的Java和PHP培訓。

下面是代碼:

<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%"> 
<thead> 
    <tr> 
     <th>ID</th> 
     <th>Message Type</th> 
     <th>Crime Type</th> 
     <th>Description</th> 
     <th>Date/Time Reported</th> 
     <th>Date/Time Committed</th> 
     <th>Sender</th> 
     <th>Status</th> 
     <th>Options</th> 
    </tr> 
</thead> 
<tfoot> 
    <tr> 
     <th>--</th> 
     <th>--</th> 
     <th>--</th> 
     <th>--</th> 
     <th>--</th> 
     <th>--</th> 
     <th>--</th> 
     <th>--</th> 
    </tr> 
</tfoot> 
<tbody> 
<?php 
$query = "SELECT reports.id, types.`name`, classifications.`name` as class, reports.description, 
concat(DATE_FORMAT(reports.committed_at,'%b %e, %Y'), ' at ', TIME_FORMAT(reports.committed_at,'%l:%i:%p')) as committed_at, 
concat(DATE_FORMAT(reports.created_at,'%b %e, %Y'), ' at ', TIME_FORMAT(reports.created_at,'%l:%i:%p')) as created_at, 
reports.casestat, users.`name` as sender, concat(status.id, ' - ', status.status) as status FROM reports 
INNER JOIN types ON reports.type_id = types.id 
INNER JOIN classifications ON reports.classification_id = classifications.id 
INNER JOIN users ON reports.created_by = users.id 
INNER JOIN status ON reports.casestat = status.id"; 

$result = mysql_query($query); 
    while($row = mysql_fetch_array($result)) 
     { 
      switch($row['casestat']){ 

       case 0: $rwcol="#ff3c3c"; break; 
       case 1: $rwcol="#ffb93c"; break; 
       case 2:$rwcol="#ffff3c"; break; 
       case 3: $rwcol="#00bc00"; break; 
       case 4: $rwcol="#5a5aff"; break; 
       }     
     echo "<tr bgcolor=$rwcol>"; 
     echo "<td id='code'>" . $row['id'] . "</td>"; 
     echo "<td>" . $row['name'] . "</td>"; 
     echo "<td>" . $row['class'] . "</td>"; 
     echo "<td>" . $row['description'] . "</td>"; 
     echo "<td>" . $row['created_at'] . "</td>"; 
     echo "<td>" . $row['committed_at'] . "</td>"; 
     echo "<td>" . $row['sender'] . "</td>"; 
     echo "<td>" . $row['status'] . "</td>"; 
     echo "<td><a onclick='updateStat(this.id)' id='".$row['id']."' href='#' ><abbr title='Edit'><i class='fa fa-edit'></i></abbr>Update Status</a> </tr>";} 
?> 

</tbody> 

下面是它的樣子:

screen

+0

我認爲故障在該行中:回聲 「」; –

+0

是@GovindSamrow,引號是它的一部分。謝謝。 – JasonT

回答

0

也許bgcolor屬性是由指定的。表條紋類覆蓋您的標籤。

.table-striped

+0

謝謝@wonyeouuu我的壞,我忘了它。 – JasonT