我遇到了问题
我尝试在TABLE(HTML)中显示数据库中的数据,然后我显示的数据必须保存在具有相同内容的另一个表中
显示数据
<?php
include('ApprovalDB.php');
$result = mysql_query("SELECT pr_id, prcode, type, client, requestdate, status FROM t_purchaserequest where status = 'Approved' and type = 'Sample Only'")
or die(mysql_error());
echo "<table class = 'tbl1' cellpadding='10'>";
echo "<thead><td>PRCODE</td><td>TYPE</td> <td>CLIENT</td> <td>REQUESTED DATE</td> <td>STATUS</td><td>ACTION</td></thead>";
while($row = mysql_fetch_array( $result )) {
echo "<tr>";
echo '<td>' . $row['prcode'] . '</td>';
echo '<td>' . $row['type'] . '</td>';
echo '<td>' . $row['client'] . '</td>';
echo '<td>' . $row['requestdate'] . '</td>';
echo '<td>' . $row['status'] . '</td>';
echo '<td><a href="returnDB.php?id=' . $row['pr_id'] . '" class = "link1">Return Item</a></td>';
echo "</tr>";
}
echo "</table>";
echo "<a href = 'javascript:window.history.go(-1);' class = 'img_arrow'><img src = 'back_arrow.png'></a>";
?>
此链接返回项目,该功能必须保存在表格中的项目显示..因为我是新手..我不知道应该从这里开始......
感谢您对我的问题的回复
答案 0 :(得分:1)
首先,不应该再以HTML格式存储细节,因为您可以随时创建。
如果您想这样做,您可以创建一个变量并将渲染HTML存储在该变量中,您可以打印相同的变量并将该变量保存在隐藏字段中。
提交带有帖子请求的表单,因为隐藏字段值的隐藏大小可能更多。
如果隐藏字段的大小更大,那么只需将记录的主键发送到服务器端,再次从DB获取详细信息,创建相同的HTML并将其存储回另一个表。
下面是将HTML存储在变量中并显示它的代码。您可以创建表单并提交我上面提到的值。
<?php
include('ApprovalDB.php');
$result = mysql_query("SELECT pr_id, prcode, type, client, requestdate, status FROM t_purchaserequest where status = 'Approved' and type = 'Sample Only'")
or die(mysql_error());
$str = "";
$str .= "<table class = 'tbl1' cellpadding='10'>";
$str .= "<thead><td>PRCODE</td><td>TYPE</td> <td>CLIENT</td> <td>REQUESTED DATE</td> <td>STATUS</td><td>ACTION</td></thead>";
while ($row = mysql_fetch_array($result)) {
$str .= "<tr>";
$str .= '<td>' . $row['prcode'] . '</td>';
$str .= '<td>' . $row['type'] . '</td>';
$str .= '<td>' . $row['client'] . '</td>';
$str .= '<td>' . $row['requestdate'] . '</td>';
$str .= '<td>' . $row['status'] . '</td>';
$str .= "</tr>";
}
$str . "</table>";
//display the data
echo $str;
//to save the data ideally you should not save in this format but still you want to do you can do in two way
//1. most appropriate way you can get the product details in server side, create same string like i have created above and save it to db
//2.create hidden field and save the data with post form
echo "<input type='hidden' name='my-data' value='".$str."' >";
echo "<a href = 'javascript:window.history.go(-1);' class = 'img_arrow'><img src = 'back_arrow.png'></a>";
?>