douwa6220 2010-07-03 09:34
浏览 18
已采纳

PHP / MySQL通过单击网站上的div更改数据库中的数据?

I have a website that displays a table of a list of people and a value of 1 or 0. If the value is 0 the cell background is green, it ifs 1 its red. How would i make it so clicking the cell will change the value (and therefore colour) and write it to the database?

Below is my code.

Many thanks, Stephen

<?
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>";


?>
  • 写回答

1条回答 默认 最新

  • douya5194 2010-07-03 09:42
    关注

    AJAX is the key. This link will help you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大