|
|
|
สอบถามการเปลี่ยนสีตัวอกษรในตารางแบบมีเงื่อนไขพอจะทำได้ไหมครับ |
|
|
|
|
|
|
|
สมมุติว่าผมต้องการเปลี่ยนสีตัวอักษร เช่น ถ้า ค่าในตารางช่อง Temperature มากกว่า 25 ให้ข้อมูลช่องนั้นเป็นตัวอักษรสีแดง และ ให้ถ้าน้อยกว่า 25 ให้เป็นสีดำ ไม่ทราบว่าพอจะทำได้หรือเปล่าครับ และ ทำยังไง (ตารางผมเป็นแบบ Dynamic Table ดึงค่าจากฐานข้อมูลนะครับ)
Code (PHP)
<?php require_once('../../../Connections/TempH.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$maxRows_Dataformdatabase = 24;
$pageNum_Dataformdatabase = 2;
if (isset($_GET['pageNum_Dataformdatabase'])) {
$pageNum_Dataformdatabase = $_GET['pageNum_Dataformdatabase'];
}
$startRow_Dataformdatabase = $pageNum_Dataformdatabase * $maxRows_Dataformdatabase;
mysql_select_db($database_TempH, $TempH);
$query_Dataformdatabase = "SELECT * FROM temp";
$query_limit_Dataformdatabase = sprintf("%s LIMIT %d, %d", $query_Dataformdatabase, $startRow_Dataformdatabase, $maxRows_Dataformdatabase);
$Dataformdatabase = mysql_query($query_limit_Dataformdatabase, $TempH) or die(mysql_error());
$row_Dataformdatabase = mysql_fetch_assoc($Dataformdatabase);
if (isset($_GET['totalRows_Dataformdatabase'])) {
$totalRows_Dataformdatabase = $_GET['totalRows_Dataformdatabase'];
} else {
$all_Dataformdatabase = mysql_query($query_Dataformdatabase);
$totalRows_Dataformdatabase = mysql_num_rows($all_Dataformdatabase);
}
$totalPages_Dataformdatabase = ceil($totalRows_Dataformdatabase/$maxRows_Dataformdatabase)-1;
?>
<!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=utf-8" />
<meta http-equiv="refresh" content="10; url="<?php echo $_SERVER['temp_dw']; ?>">
<title>Temperature</title>
<script type="text/javascript">
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
</script>
<style type="text/css">
body,td,th {
color: #000;
font-size: 15px;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
}
body {
background-image: url();
}
</style>
</head>
<body onload="MM_preloadImages('images/images/15_03.jpg','images/images/15_05.jpg','images/images/15_06.jpg','images/images/15_07.jpg')">
<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3" align="center"><img src="images/images/15_01.jpg" width="1024" height="231" /></td>
</tr>
<tr>
<td width="300" height="0" valign="top"> </td>
<th width="724" colspan="2" rowspan="4" valign="top" bgcolor="#FFFFFF"><p> </p>
<table width="500" border="0" align="center">
<tr>
<td width="166" height="31" bgcolor="#0099FF"><div align="center"><font color= "#FFFFFF"><font size ="5px"> Date </font></font></div></td>
<td bgcolor="#0099FF"><div align="center"><font color= "#FFFFFF"><font size ="5px"> Temperature</font></font></div></td>
<td width="166" bgcolor="#0099FF"><div align="center"><font color= "#FFFFFF"><font size ="5px"> Humidity</font></font></div></td>
</tr>
<?php do { ?>
<tr>
<td bgcolor="#E0FFFF"><?php echo $row_Dataformdatabase['Date']; ?></td>
<td bgcolor="#E0FFFF"><?php echo $row_Dataformdatabase['Temperature']; ?></td>
<td bgcolor="#E0FFFF"><?php echo $row_Dataformdatabase['Humidity']; ?></td>
</tr>
<?php } while ($row_Dataformdatabase = mysql_fetch_assoc($Dataformdatabase)); ?>
</table>
<p> </p>
<p> </p> </th>
</tr>
<tr valign="top"></tr>
<tr valign="top"></tr>
<tr valign="top">
<th height="0" valign="top"><table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top"><a href="index.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image4','','images/images/15_03.jpg',1)"><img src="images/15_03.jpg" width="322" height="103" id="Image4" /></a></td>
</tr>
<tr>
<td valign="top"><a href="../../../เลือกปี.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image5','','images/images/15_05.jpg',1)"><img src="images/15_05.jpg" width="322" height="103" id="Image5" /></a></td>
</tr>
<tr>
<td valign="top"><a href="Charts.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image6','','images/images/15_06.jpg',1)"><img src="images/15_06.jpg" width="322" height="100" id="Image6" /></a></td>
</tr>
<tr>
<td valign="top"><a href="ผู้จัดทำ.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image7','','images/images/15_07.jpg',1)"><img src="images/15_07.jpg" width="322" height="104" id="Image7" /></a></td>
</tr>
</table></th>
</tr>
<tr>
<td colspan="3" align="center"><img src="images/ex1---Copy_02.jpg" width="1029" height="93" /></td>
</tr>
</table>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Dataformdatabase);
?>
Tag : PHP, MySQL, HTML
|
|
|
|
|
|
Date :
2018-06-20 15:00:20 |
By :
knesza29 |
View :
2378 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<td bgcolor="#E0FFFF"><?php echo $row_Dataformdatabase['Temperature']; ?></td>
เปลี่ยนเป็น
<td bgcolor="<?php $row_Dataformdatabase['Temperature'] >25 ? 'red' : 'black'; ?>"><?php echo $row_Dataformdatabase['Temperature']; ?></td>
|
|
|
|
|
Date :
2018-06-21 02:13:27 |
By :
deawx |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<td bgcolor="<?php echo $row_Dataformdatabase['Temperature'] >25 ? 'red' : 'black'; ?>"><?php echo $row_Dataformdatabase['Temperature']; ?></td>
แก้ไขตกหล่นให้ครับ
ปล. แต่ผมจะใช้ <?=($row_Dataformdatabase['Temperature'] >25 ? 'red' : 'black')?>
ซึ่งรูปแบบ <?=$var?> เป็นรูปแบบหนึ่งในการใช้่งานของ tag php ในการ echo ข้อมูล และเป็นรูปแบบมาตรฐานของ PHP
ไม่ใช่ short tag เฃ่น <? echo 'abc'; ?>
เมื่อคุณ ปิด short_tag แล้ว <?=$var?> ก็ยังใช้งานได้อยู๋
|
ประวัติการแก้ไข 2018-06-21 11:24:03
|
|
|
|
Date :
2018-06-21 11:05:48 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|