我有一个网站,显示人员列表和值1或0。如果值为0,则单元格背景为绿色,如果为1,则为红色。如何点击单元格将更改值(因此颜色)并将其写入数据库?
以下是我的代码。
非常感谢, 斯蒂芬
<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM name";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "<b><center>Database Output</center></b><br><br>";
?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">InOut</font></th>
</tr>
<?
$i=0;
while ($i < $num) {
$name=mysql_result($result,$i,"Name");
$inout=mysql_result($result,$i,"InOut");
?>
<?
{
if ($inout == 0) {
$tablecolour = "FF0000";
}
else {
$tablecolour = "458B00";
}
}
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$name"; ?></font></td>
<td bgcolor=<? echo "$tablecolour"; ?>><font face="Arial, Helvetica, sans-serif"><? echo "$inout"; ?></font></td>
</tr>
<?
++$i;
}
echo "</table>";
?>