【发布时间】:2017-09-27 12:36:11
【问题描述】:
我一直在建立一个数据库来计算终止费。
下面的代码(termination.php)从前一页的复选框中选择多行,处理查询,并循环输出到一个简单的 HTML 表。这是按要求工作的。
<?php
require_once '.\Includes\dbcon.php';
$rowCount = count($_POST["select"]);
for ($i = 0; $i < $rowCount; $i++)
{
$sql = "UPDATE `{$_POST['customer']}` SET `DateOfCancellation`='{$_POST['dateofcancellation']} WHERE ServiceID={$_POST['select'][$i]}'";
if ($con->query($sql) === TRUE)
{
echo "";
}
else
{
echo "Error: " . $sql . "<br />" . $con->error;
}
}
?>
<a href = ".\index.php">Back to Index</a></p>
<strong>Termination for <?php echo ucwords($_POST['customer']) ?> Based on Cancellation Date <?php echo $_POST['dateofcancellation'] ?></strong></p>
<table>
<tr>
<th>Service Name</th>
<th>License Start Date</th>
<th>License End Date</th>
<th>Cost Per Calendar Month</th>
<th>Balance on Termination</th>
<?php
$rowCount = count($_POST["select"]);
for ($i = 0; $i < $rowCount; $i++)
{
$sql = mysqli_query($con, "$select FROM `{$_POST['customer']}` WHERE ServiceID={$_POST['select'][$i]}");
$row[$i] = mysqli_fetch_array($sql); ?>
<tr>
<td><?php
echo $row[$i]['ServiceName']; ?></td>
<td><?php
echo $row[$i]['LicenseStart']; ?></td>
<td><?php
echo $row[$i]['LicenseEND']; ?></td>
<td>£<?php
echo $row[$i]['CostPCM']; ?></td>
<td>£<?php
echo $row[$i]['CostOfTermination']; ?></td>
<?php
}
$sql = "UPDATE `{$_POST['customer']}` SET `DateOfCancellation`='0000-00-00'";
if ($con->query($sql) === TRUE)
{
echo "";
}
else
{
echo "Error: " . $sql . "<br />" . $con->error;
}
$sum = 0;
for ($i = 0; $i < $rowCount; $i++)
{
$sum = $sum + $row[$i]['CostOfTermination'];
}
echo "<strong>The Total Balance of Termination is: </strong>£" . $sum;
echo "<p>";
$sum = 0;
for ($i = 0; $i < $rowCount; $i++)
{
$sum = $sum + $row[$i]['CostPCM'];
}
echo "<strong>Balance of Termination per Month: </strong>£" . $sum;
echo "<p>";
?>
</tr>
我需要做什么才能将表中的数据导出到 Excel 文件(理想情况下)或 CSV 文件。我尝试了几种不同的方法,可以获取标题但不能获取实际数据。我认为 for 循环是让我失望的原因。
【问题讨论】:
-
最好将您的代码发布到实际问题中。外部链接坏了。
-
我建议编辑您的答案,包括您在外部源中链接的代码。随意只保留最相关的部分
-
已接受。感谢那里的建议!
-
您需要做的就是回显一行以逗号分隔的列标题名称(原始文本)
,,然后回显通常包含在<td></td>中但由一个分隔的每个值再次逗号。这与回显到 HTML 表格中的过程相同,只是没有表格代码