|
|
|
php ช่วยดูหน่อยคับว่าจะใส่สีข้อความตามสถาน่ะ status ในตารางให้แตกต่างกันได้ยังไงแก้ให้หน่อยนะ |
|
|
|
|
|
|
|
ช่วยดูหน่อยคับว่าจะใส่สีข้อความในตารางให้แตกต่างกันได้ยังไงแก้ให้หน่อยนะ
รูปนี้จะแสดงข้อความจะฐานข้อมูลแต่สีในข้อความในตารางมันเป็นสีดำเหมือนกันผมไม่รู้จะแก้ยังไงโดยผมอยากให้
Used = สีเขียว
Spare =น้ำเงิน
Empty = สีแดง
Tank Damage = เทา
นี่คือโค๊ดแบบฟรอม
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
<style>
body{
font-size:12px;
margin:0px;
padding:0px;
}
</style>
</head>
<body>
<?php
mysql_connect("localhost", "root", "test") or die(mysql_error());
mysql_select_db(testmember) or die(mysql_error());
$yesterday= "06.05.11";
$today="11.05.11";
$data = "SELECT * FROM status WHERE datetime >='$yesterday' AND datetime<='$today'";
$rss=mysql_query($data);
//print $data;
print "<table width='100' border='1' cellpadding='0' cellspacing='0' align=center>";
print "<tr>";
print "<td width='90' height='26' bgcolor='#99FF99' ><div align='center'><strong>Nitrogen Tank No.1</strong></div></td>";
print "<td width='90' height='26' bgcolor='#99FF99' ><div align='center'><strong>Nitrogen Tank No.2</strong></div></td>";
print "<td width='90' height='26' bgcolor='#99FF99' ><div align='center'><strong>Nitrogen Tank No.3</strong></div></td>";
print "<td width='90' height='26' bgcolor='#99FF99' ><div align='center'><strong>Nitrogen Tank No.4</strong></div></td>";
print "<td width='90' height='26' bgcolor='#99FF99' ><div align='center'><strong>Nitrogen Tank No.5</strong></div></td>";
print "<td width='90' height='26' bgcolor='#99FF99' ><div align='center'><strong>Nitrogen Tank No.6</strong></div></td>";
print "<td width='90' height='26' bgcolor='#99FF99' ><div align='center'><strong>Nitrogen Tank No.7</strong></div></td>";
print "<td width='90' height='26' bgcolor='#99FF99' ><div align='center'><strong>Nitrogen Tank No.8</strong></div></td>";
print "<td width='90' height='26' bgcolor='#99FF99' ><div align='center'><strong>Nitrogen Tank No.9</strong></div></td>";
print "<td width='90' height='26' bgcolor='#99FF99' ><div align='center'><strong>Nitrogen Tank No.10</strong></div></td>";
print "<td width='90' height='26' bgcolor='#99FF99' ><div align='center'><strong>Nitrogen Tank No.11</strong></div></td>";
print "<td width='90' height='26' bgcolor='#99FF99' ><div align='center'><strong>Nitrogen Tank No.12</strong></div></td>";
print "<td width='90' height='26' bgcolor='#99FF99' ><div align='center'><strong>Nitrogen Tank No.13</strong></div></td>";
print "<td width='90' height='26' bgcolor='#99FF99' ><div align='center'><strong>Nitrogen timestamp</strong></div></td>";
print "<td width='90' height='26' bgcolor='#99FF99' ><div align='center'><strong>Nitrogen datetime</strong></div></td>";
print "<td width='90' height='26' bgcolor='#99FF99' ><div align='center'><strong>Nitrogen time</strong></div></td>";
print "</tr>";
while($info = mysql_fetch_array( $rss ))
{
print "<tr>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no1]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no2]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no3]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no4]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no5]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no6]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no7]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no8]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no9]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no10]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no11]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no12]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no13]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[timestamp]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[datetime]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[time]."</strong></div></td>";
print "</tr>";
}
print "</table>";
print "</body>";
?>
</html>
ส่วนนี่คือโค๊ด sql ไว้ทดลองคับ
Code (PHP)
-- phpMyAdmin SQL Dump
-- version 2.10.3
-- http://www.phpmyadmin.net
--
-- โฮสต์: localhost
-- เวลาในการสร้าง: 11 พ.ค. 2011 น.
-- รุ่นของเซิร์ฟเวอร์: 6.0.4
-- รุ่นของ PHP: 6.0.0-dev
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- ฐานข้อมูล: `testmember`
--
-- --------------------------------------------------------
--
-- โครงสร้างตาราง `status`
--
CREATE TABLE `status` (
`no1` varchar(14) NOT NULL,
`no2` varchar(14) NOT NULL,
`no3` varchar(14) NOT NULL,
`no4` varchar(14) NOT NULL,
`no5` varchar(14) NOT NULL,
`no6` varchar(14) NOT NULL,
`no7` varchar(14) NOT NULL,
`no8` varchar(14) NOT NULL,
`no9` varchar(14) NOT NULL,
`no10` varchar(14) NOT NULL,
`no11` varchar(14) NOT NULL,
`no12` varchar(14) NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`datetime` text NOT NULL,
`time` time NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- dump ตาราง `status`
--
INSERT INTO `status` VALUES ('Tank Damage', 'Empty', 'Used', 'Empty', 'Spare', 'Empty', 'Spare', 'Empty', 'Tank Damage', 'Spare', 'Used', 'Spare', '2011-05-11 13:47:05', '11.05.11', '00:00:00');
INSERT INTO `status` VALUES ('Tank Damage', 'Empty', 'Used', 'Empty', 'Spare', 'Empty', 'Spare', 'Empty', 'Tank Damage', 'Spare', 'Used', 'Spare', '2011-05-11 14:04:41', '11.05.11', '00:00:00');
INSERT INTO `status` VALUES ('Tank Damage', 'Empty', 'Used', 'Empty', 'Used', 'Empty', 'Spare', 'Empty', 'Tank Damage', 'Spare', 'Used', 'Spare', '2011-05-11 14:07:05', '11.05.11', '00:00:00');
INSERT INTO `status` VALUES ('Tank Damage', 'Empty', 'Used', 'Empty', 'Used', 'Empty', 'Spare', 'Empty', 'Tank Damage', 'Spare', 'Used', 'Spare', '2011-05-11 14:08:21', '11.05.11', '00:00:00');
INSERT INTO `status` VALUES ('Spare', 'Empty', 'Used', 'Empty', 'Used', 'Empty', 'Spare', 'Empty', 'Tank Damage', 'Spare', 'Used', 'Spare', '2011-05-11 14:16:42', '11.05.11', '00:00:00');
INSERT INTO `status` VALUES ('Spare', 'Empty', 'Used', 'Empty', 'Used', 'Empty', 'Spare', 'Empty', 'Tank Damage', 'Spare', 'Used', 'Spare', '2011-05-11 14:27:30', '11.05.11', '00:00:00');
INSERT INTO `status` VALUES ('Tank Damage', 'Empty', 'Used', 'Empty', 'Used', 'Empty', 'Spare', 'Empty', 'Tank Damage', 'Spare', 'Used', 'Spare', '2011-05-11 14:57:30', '11.05.11', '00:00:00');
INSERT INTO `status` VALUES ('Tank Damage', 'Empty', 'Used', 'Empty', 'Used', 'Empty', 'Spare', 'Empty', 'Tank Damage', 'Spare', 'Used', 'Spare', '2011-05-11 15:38:16', '11.05.11', '00:00:00');
Tag : PHP, CakePHP
|
|
|
|
|
|
Date :
2011-05-11 16:01:42 |
By :
sambeem001 |
View :
1478 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
while($info = mysql_fetch_array( $rss ))
{
$i++;
if($info[status]=="1")
{
$bg = "red";
}
elseiff($info[status]=="2")
{
$bg = "green";
}
print "<tr bgcolor=\"$bg\">";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no1]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no2]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no3]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no4]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no5]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no6]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no7]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no8]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no9]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no10]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no11]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no12]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[no13]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[timestamp]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[datetime]."</strong></div></td>";
print "<td height='33' bgcolor='#99FF99'><div align='center'><strong>".$info[time]."</strong></div></td>";
print "</tr>";
}
เขียนต่อเอาเองครับ
|
|
|
|
|
Date :
2011-05-12 13:18:19 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|