如何使用php将颜色更改保存在表中


how to save colour changes in table using php

如何将颜色保存到数据库中?这是我的编码。。我可以更改表格的颜色,但无法保存到数据库中。当我再次打开它时,颜色会变为正常。。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<html>
<title>Test</title>
<head>
<script type="text/javascript">
function colourRow1(rowNumber) {
    //some code to change the colour of the row indicated by the number
    alert("change row 1 background colour");
    var tr = document.getElementById('table1')
                 .getElementsByTagName('tr')[rowNumber-1];
    tr.style.backgroundColor = 'blue';

}
</script>
</head>
<body>
<table name="table1" id="table1" border="1">
<thead>
<th>heading1</th>
<th>heading2</th>
<th>heading3</th>
</thead>
<tbody>
<tr id="row1">
<td>1,1</td>
<td>1,2</td>
<td>1,3</td>
</tr>
<tr id="row2">
<td>2,1</td>
<td>2,2</td>
<td>2,3</td>
</tr>
<tr id="row3">
<td>3,1</td>
<td>3,2</td>
<td>3,3</td>
</tr>
</tbody>
</table>
<button type="button"  onClick="colourRow1(1)" action="colourupdate.php">Change Row 1</button>
</body>
</html>

如何将颜色保存到数据库中?这是我的编码。。我可以更改表格的颜色,但无法保存到数据库中。当我再次打开它时,颜色会变为正常。。

您需要维护另一个表来存储颜色历史。。类似的表格结构

id | rowno | color

您需要使用ajax调用为每次单击按钮存储行号和颜色。

其他方法是将行id和颜色存储为特定时间段的会话。。

$_SEESION['rowid']=$value;
$_SEESION['rowid']=$color;