我有以下工作来打印SQL表中的数据。但是,我有两个目标。
-
有一个信用卡字段,我也想用来创造每日值的价值。这就是我真正想打印的。但是,随着数据返回一段时间,我不想在SQL端具有每日的值,我不想手动更新数据库。
-
一旦我获得日常工作的工作,我想将其添加为每月的价值。
老实说,如果我能弄清楚如何将数据从.$data['CashTotal']
中获取。我可能会弄清楚如何自己计算一切。
最终目标是拥有一张PHP表,该表显示了一个月(每天)的日期和每日总计,然后在底部进行总计。
我无法弄清楚搜索的术语,向我展示我想做什么。
$result = mysql_query("SELECT * from HP_Closing_Count WHERE '2017-01-01' <= Date and Date < '2017-02-01'");
echo '<table border=2px>'; // opening table tag
echo'<th>Date</th>
<th>Employee</th>
<th>CashTotal</th>
'; //table headers
while($data = mysql_fetch_array($result))
{
// we are running a while loop to print all the rows in a table
echo'<tr>'; // printing table row
echo '<td>'.$data['Date'].'</td>
<td>'.$data['Employee'].'</td>
<td>'.$data['CashTotal'].'</td>
'; // we are looping all data to be printed till last row in the table
echo'</tr>'; // closing table row
}
echo '</table>'; //closing table tag
?>
日期员工CashTotal
2017-01-04乔恩931.25
2017-01-05 Robin 0
2017-01-07乔恩383.5
2017-01-06 Jay 275.25
2017-01-08乔恩417.5
2017-01-09 Jay 297.75
2017-01-10 Colwyn C 280.5
2017-01-11 Colwyn 344
2017-01-12 Ellen 374.5
2017-01-13 Jay 288.5
2017-01-14 Jay 377.75
2017-01-15 Jay 349.25
2017-01-16 Jay 376.5
2017-01-17 Colwyn 248.5
2017-01-18泰勒210.5
2017-01-19 Colwyn 247
2017-01-20 Jay 330.75
2017-01-21 Jay 475.75
2017-01-22 Jay 489.75
2017-01-23 Jay 344
2017-01-24帕克321.25
2017-01-25泰勒257.25
2017-01-26 Ellen 249
2017-01-27 Jay 318.25
2017-01-28 Jay 477
2017-01-29 Jay 382
2017-01-30 Jay 271.5
2017-01-31 Ellen 230.25
在您用来生成表的循环中,您可以按$ data ['cashtotal']的运行总和来计算。然后将其用于您的总体显示。
$grandTotal = 0;
while($data = mysql_fetch_array($result))
{
// we are running a while loop to print all the rows in a table
echo'<tr>'; // printing table row
echo '<td>'.$data['Date'].'</td>
<td>'.$data['Employee'].'</td>
<td>'.$data['CashTotal'].'</td>
'; // we are looping all data to be printed till last row in the table
echo'</tr>'; // closing table row
$grandTotal += $data['CashTotal'];
}
echo '</table>'; //closing table tag
echo 'Total: ' . $grandTotal;
$TOTAL=0;
$result = mysql_query("SELECT * from HP_Closing_Count WHERE '2017-01-01' <= Date and Date < '2017-02-01'");
echo '<table border=2px>'; // opening table tag
echo'<th>Date</th>
<th>Employee</th>
<th>CashTotal</th>
'; //table headers
while($data = mysql_fetch_array($result))
{
$TOTAL=$TOTAL+$data['CashTotal'];
// we are running a while loop to print all the rows in a table
echo'<tr>'; // printing table row
echo '<td>'.$data['Date'].'</td>
<td>'.$data['Employee'].'</td>
<td>'.$data['CashTotal'].'</td>
'; // we are looping all data to be printed till last row in the table
echo'</tr>'; // closing table row
}
echo '</table>'; //closing table tag
echo $TOTAL;
?>
日期员工CashTotal
2017-01-04乔恩931.25
2017-01-05 Robin 0
2017-01-07乔恩383.5
2017-01-06 Jay 275.25
2017-01-08乔恩417.5
2017-01-09 Jay 297.75
2017-01-10 Colwyn C 280.5
2017-01-11 Colwyn 344
2017-01-12 Ellen 374.5
2017-01-13 Jay 288.5
2017-01-14 Jay 377.75
2017-01-15 Jay 349.25
2017-01-16 Jay 376.5
2017-01-17 Colwyn 248.5
2017-01-18泰勒210.5
2017-01-19 Colwyn 247
2017-01-20 Jay 330.75
2017-01-21 Jay 475.75
2017-01-22 Jay 489.75
2017-01-23 Jay 344
2017-01-24帕克321.25
2017-01-25泰勒257.25
2017-01-26 Ellen 249
2017-01-27 Jay 318.25
2017-01-28 Jay 477
2017-01-29 Jay 382
2017-01-30 Jay 271.5
2017-01-31 Ellen 230.25
9549