본문 바로가기
MySql

MySQL MYSQL 값을 기반으로 특정 색상으로 셀 PHP 강조

by 베이스 공부 2020. 12. 28.
반응형

"ProspectStatus"필드에 대해 mysql의 테이블 / 열 , RED, GREEN, YELLOW에서 표시 할 수있는 세 가지 값이 있습니다.

어쨌든 값에 따라 셀의 배경색을 변경할 수 있습니까?

예 :

echo "<td>" . $row['ProspectStatus'] . "</td>";

PHP 코드 :

 $result = mysql_query("SELECT * FROM customerdetails"); 
//List the Columns for the Report 
echo "<table border='1'> 
<tr> 
<th>CustomerID</th> 
<th>Customer Name</th> 
<th>Prospect Status</th> 
<th>Address</th> 
</tr>"; 

while($row = mysql_fetch_array($result)) 
  { 
  echo "<tr>"; 
  echo "<td>" . $row['CustomerID'] . "</td>"; 
  echo "<td>" . $row['CustomerName'] . "</td>"; 
  echo "<td>" . $row['ProspectStatus'] . "</td>"; //this is the field I want to show either RED, GREEN or YELLOW 
  echo "<td>" . $row['Address'] . "</td>"; 
  echo "</tr>"; 
  } 
echo "</table>";  

 

해결 방법

 

다음과 같이 할 수 있습니다.

while($row = mysql_fetch_array($result)) 
  { 
  echo "<tr>"; 
  echo "<td>" . $row['CustomerID'] . "</td>"; 
  echo "<td>" . $row['CustomerName'] . "</td>"; 
  if($row['ProspectStatus']=='[val1]') // [val1] can be 'approved'
         echo "<td style='background-color: #00FF00;'>".$row['ProspectStatus']."</td>"; 
  else if($row['ProspectStatus']=='[val2]')// [val2]can be 'rejected'
         echo "<td style='background-color: #FF0000;'>".$row['ProspectStatus']."</td>"; 
  else if($row['ProspectStatus']=='[val3]') //[val3] can be 'on hold'
         echo "<td style='background-color: #FFFF00;'>".$row['ProspectStatus']."</td>"; 
  echo "<td>" . $row['Address'] . "</td>"; 
  echo "</tr>"; 
  } 
echo "</table>";  

상태 값은 색상에 따라 달라질 수 있습니다. val1 , val2 val3 이 3 가지 색상의 값이라고 가정합니다.

 

참조 페이지 https://stackoverflow.com/questions/17462388

 

 

반응형

댓글