我有桌子。该表有10行4列(即:Sl.No.,Project Name,ChangeDate,Changed By)。当我在项目名称中修改时,在相应的changeDate列中如何使用php自动将日期更改为今天的日期?
这是我的代码:
<html>
<head>
<title>Project</title>
<script>
function GetCellValues()
{
var str = '';
var rows = document.getElementsByTagName('tr');
var table=document.getElementById("project");
for (var i=0;i<table.rows[0].cells.length;i++)
{
if (i > 2 )
{
str = str + table.rows[0].cells[3].innerHTML.replace(", ");
}
else
{
str = str + (table.rows[0].cells[i].innerHTML) + ', ' ;
}
}
for (var c = 1 ; c < rows.length ; c++)
{
str += '\n' + "0" + c + ', ';
var row = rows[c];
var inputs = row.getElementsByTagName('input');
for (var k = 0 ; k < inputs.length ; k++)
if (k > 1)
{
str += inputs[k].value.replace(", ");
}
else
{
str += inputs[k].value + ', ';
}
}
document.getElementById('hide').value = str;
//alert(document.getElementById('hide').value);
}
</script>
</head>
<body background="floor.jpg">
<form action = "" method = "POST">
<br>
<h1><center><u>PROJECT</u> :</center></h1>
<br>
<input type="hidden" id="hide" name="hide" value="">
<input type="submit" name="submit" onclick = "GetCellValues()" value = "SAVE" />
<br>
<table id = "project" border= "1" cellpadding="10" cellspacing="0"
style = "border-color: brown; background-color:silver;margin-left: auto; margin-right: auto; width:60%">
<tr>
<th align="center" width="10%" id = "Sl.No." >Sl.No.</th>
<th align="center" width="30%" id = "Project Name" >Project Name</th>
<th align="center" width="30%" id = "ChangeDate" >ChangeDate</th>
<th align="center" width="30%" id = "Changed By" >Changed By</th>
</tr>
</table>
</form>
<?php
$handle = fopen("data.txt", "r+");
$hide = $_REQUEST['hide'];
fwrite($handle,$hide);
?>
<?php
$file = file('data.txt');
$lines = count($file);
$dtFormatted = date("m-d-Y");
echo'<table id = "project" border= "1" cellpadding="10" cellspacing="0"
style = "border-color: brown; background-color:silver;margin-left: auto; margin-right: auto; width:60%">';
for ($i=1; $i<$lines; $i++)
{
$part = explode(',', $file[$i]);
echo'<tr>
<td align= "center" width="10%">'.$part[0].'</td>
<td align= "center" width="30%"><input type="text" placeholder="Text Box" value='.$part[1].'></td>
<td align= "center" width="30%"><input type="text" value='.$dtFormatted.'></td>
<td align= "center" width="30%"><input type="text" placeholder="Text Box" value='.$part[3].'></td>
</tr>';
}
echo'</table>';
?>
</body>
</html>
答案 0 :(得分:0)
将mysql中的更改日期字段定义为
changeDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
使用该定义,更改日期字段始终包含上次修改的日期和时间。 Mysql会处理它,你不需要在PHP中完成它。