-6ren">
gpt4 book ai didi

php - 如何使用 PHP 和 MySQL 显示按归档分组的报告?

转载 作者:行者123 更新时间:2023-11-29 00:18:11 26 4
gpt4 key购买 nike

我想概括按月分组的报告。但是 sum 的结果是不正确的。它只是汇总一个月的数据并显示在所有行中。

<?php
$query = mysql_query("SELECT * FROM barang GROUP BY arsip");

$i = 1;

while ($data = mysql_fetch_assoc($query)) {
?>
<tr class="<?php if ($i % 2 == 0) { echo "odd"; } else { echo "even"; } ?>">
<td><?php echo $i; ?></td>

<td><?php echo $data['arsip']; ?></td>



<td><?php
$Masuk= mysql_query("SELECT SUM(barang_in) AS masuk FROM barang GROUP BY arsip");

if($Masuk){
$data = mysql_fetch_assoc($Masuk);
echo $data['masuk'];
}
?></td>

<td><?php
$keluar= mysql_query("SELECT SUM(bijih_out+htm_out+pth_out) AS keluar FROM barang GROUP BY arsip");

if($keluar){
$data = mysql_fetch_assoc($keluar);
echo $data['keluar'];
}?></td>

<td><?php
$efisiensi= mysql_query("SELECT SUM((bijih_out+htm_out+pth_out)-barang_in) AS efisiensi FROM barang GROUP BY arsip");

if($efisiensi){
$data = mysql_fetch_assoc($efisiensi);
echo $data['efisiensi'];
}
?></td>

<td><?php
$persen= mysql_query("SELECT SUM(barang_in/(bijih_out+htm_out+pth_out))*1 AS persen FROM barang GROUP BY arsip");
$simbol = "%";

if($persen){
$data = mysql_fetch_assoc($persen);
echo number_format($data['persen'],2); echo $simbol;
}
?></td>





<?php
$i++;
}

?>

这就是我的代码。这有什么问题吗?有一些列用于显示收入项、结果项、效率(结果和收入项的差异)和效率百分比。

最佳答案

我终于找到了正确的代码。感谢@RandomSeed 帮助我。这是我的最终代码,它有效!

<?php
$query = mysql_query("SELECT arsip, SUM(barang_in) AS income, SUM(bijih_out+htm_out+pth_out) AS outcome, SUM((bijih_out+htm_out+pth_out
)-barang_in) AS efficiency, SUM((barang_in / ( bijih_out + htm_out + pth_out))*100) AS percent FROM barang GROUP BY arsip");

$i = 1;

while ($data = mysql_fetch_assoc($query)) {
?>
<tr class="<?php if ($i % 2 == 0) { echo "odd"; } else { echo "even"; } ?>">
<td><?php echo $i; ?></td>

<td><?php echo $data['arsip']; ?></td>



<td><?php echo $data['income']; ?></td>


<td><?php echo $data['outcome']; ?></td>


<td><?php echo $data['efficiency']; ?></td>

<td><?php $simbol = "%"; echo number_format($data['percent'],0); echo $simbol; ?></td>





<?php
$i++;
}

?>

关于php - 如何使用 PHP 和 MySQL 显示按归档分组的报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22115859/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com