有人可以帮我的系统吗。我在将每个日期的计算数据存储到我构建的表中时遇到了一些问题。问题是,当第一个日期数据被计算时,它会存储在第一列,但当第二个日期数据计算时,我的所有计算都只包含在一列中。例如:开始日期为2020年4月9日至2020年9月5日,情况如下:
此部分的代码:
if(isset($_POST["from_date"], $_POST["to_date"])) {
$day =date("d", strtotime($_POST["from_date"]));
$end =date("d", strtotime($_POST["to_date"]));
?><table class="table table-bordered">
<tr>
<th width="10%">Date testing 2</th> <?php
for($i=$day; $i<=$end; $i++){
?><th width="10%"><?php echo $i?></th><?php
}
?>
<th width="10%">Total</th>
<th width="10%">Balance To Go</th>
</tr> <?php
if(mysqli_num_rows($resultR) > 0){
if(isset($_POST["FighterID"]) and !empty($_POST["FighterID"])){
/..../
}else{
// second table
while($rowF = $resultX -> fetch_assoc()){// registerfighter
$totalPlus = 0;
//table start
?> <tr>
<td><?php echo 'ID = '.$rowF["UserID"] ?></td>
<?php
$resultR -> data_seek(0);
while($rowR = $resultR -> fetch_assoc()){// by record
$resultY-> data_seek(0);
while($rowY = $resultY -> fetch_assoc()){// by addplan
if( ($rowF["UserID"]===$rowR["UserIDD"]) and ( ($rowR["No_Plan"]) !== '1' and ($rowY["No_Plan"] === $rowR['No_Plan']) ) ){
$total = ($rowR["UserInputNEW"] + $rowR["UserInputNMP"]);
$totalPlus = $totalPlus + $total;
/*?><td> <?php echo '';?></td> <?php*/
}
}
}
?>
<td><?php echo 'Totaling A8 / RP8 = '.$totalPlus; ?></td>
<td><?php echo 'Total A8 / RP8 = '.$totalPlus; ?></td>
<td><?php echo 'Balance A8 / RP8 = '.( 40 - $totalPlus); ?></td>
</tr>
<?php
//table end
}
}
此处为problemsenter图像描述假设图像描述这里
您应该打印while循环内的单个计算和while循环外的总计算。试试这个
if(isset($_POST["from_date"], $_POST["to_date"])) {
$day =date("d", strtotime($_POST["from_date"]));
$end =date("d", strtotime($_POST["to_date"]));
?><table class="table table-bordered">
<tr>
<th width="10%">Date testing 2</th> <?php
for($i=$day; $i<=$end; $i++){
?><th width="10%"><?php echo $i?></th><?php
}
?>
<th width="10%">Total</th>
<th width="10%">Balance To Go</th>
</tr> <?php
if(mysqli_num_rows($resultR) > 0){
if(isset($_POST["FighterID"]) and !empty($_POST["FighterID"])){
/..../
}else{
// second table
while($rowF = $resultX -> fetch_assoc()){// registerfighter
$totalPlus = 0;
//table start
?> <tr>
<td><?php echo 'ID = '.$rowF["UserID"] ?></td>
<?php
$resultR -> data_seek(0);
while($rowR = $resultR -> fetch_assoc()){// by record
$resultY-> data_seek(0);
while($rowY = $resultY -> fetch_assoc()){// by addplan
if( ($rowF["UserID"]===$rowR["UserIDD"]) and ( ($rowR["No_Plan"]) !== '1' and ($rowY["No_Plan"] === $rowR['No_Plan']) ) ){
$total = ($rowR["UserInputNEW"] + $rowR["UserInputNMP"]);
$totalPlus = $totalPlus + $total;
echo "<td>Totaling A8 / RP8 = ".$totalPlus."</td>";
}
}
}
?>
<td><?php echo 'Balance A8 / RP8 = '.( 40 - $totalPlus); ?></td>
</tr>
<?php
//table end
}
}