【发布时间】:2013-12-04 02:04:23
【问题描述】:
我从 CSV 文件中检索数据并使用 PHP 将其存储在表中。在此表中,我使用 td 中的文本框,我可以在其中编辑表数据。 现在我想将此编辑后的数据存储在 CSV 文件中,但我无法将编辑后的数据从该表存储到 CSV 文件中。
这是我的代码:
<html>
<head>
</head>
<body>
<div>
<br>
<h1 style="text-align: center">* * * PROJECTS * * *</h1>
<br>
<input type = "hidden" id = "hide" name = "hide" value = "">
<input type = "button" name = "submit" onclick = "document.write('<?php echoAlert() ?>');" Value = "SAVE">
<br>
</div>
<?php
function echoAlert()
{
// 我必须在这里写什么才能将数据存储在 CSV 文件中?
}
?>
<?php
$handle = fopen("data.csv", "w"); // this is my .csv file.
$hide = $_REQUEST['hide']; // here I will retrieve the data from data.csv file
fwrite($handle,$hide); // Here I will write the data from file to table
$file = file('data.csv');
$lines = count($file);
这是我的桌子,我在这里写文件。
echo'<table id = "projest" border = "1" cellpadding="2" cellspacing="0"
style = "width: 60%; margin-left: auto; margin-right: auto; border-color: brown; background-color:gray;">';
for ($i=1; $i<$lines; $i++)
{
$part = explode(',', $file[$i]);
echo'<tr>
<td align= "center" width="5%">'.$part[0].'</td>
<td align= "center" width="25%"><input type="text" value='.$part[1].'></td>
<td align= "center" width="25%"><input type="text" value='.$part[2].'></td>
<td align= "center" width="25%"><input type="text" value='.$part[3].'></td>
</tr>';
}
echo'</table>';
?>
在这里我可以编辑数据....问题是我想将编辑后的数据存储在同一个 csv 文件中。但无法存储。
请给我一些代码来将此表数据存储在 CSV 文件中。
</body>
</html>
【问题讨论】:
标签: javascript php html html-table export-to-csv