views:

26

answers:

1

Hi Guys,

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


?>
A: 

AJAX is the key. This link will help you.

usef_ksa