반응형
"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
반응형
'MySql' 카테고리의 다른 글
MySQL 외래 키와 MySQL 다 대다 관계 (0) | 2020.12.28 |
---|---|
MySQL 오늘 날짜가 발생하는지 어떻게 확인합니까? (0) | 2020.12.28 |
MySQL GROUP_CONCAT에서 COUNT 사용 (0) | 2020.12.28 |
MySQL mysql이 내 localhost에서 서비스를 시작할 수 없습니다. (0) | 2020.12.28 |
MySQL PHP로 MySQL에 사용자가 이미 존재하는지 확인하는 방법 (0) | 2020.12.28 |
댓글