添加“排名”的最佳方式是什么? PHP 生成的表中的列?求列的总数/平均值?
我正在努力生成一份 PHP/MySQL 报告,该报告比较零售商店列表当前和去年的销售数据。
所有数据均来自 SQL 数据库。关键点在于,报告需要显示今年商店的排名情况以及去年的排名情况。
表格应该是这样的。
https://i.sstatic.net/trEsO.png
这是我的代码的相关部分。
$this->result = mysql_query($totalSalesQuery);
echo "<table>";
while($rows = mysql_fetch_object($this->result))
{
echo "<tr>";
echo "<td>" .$rows->store . "</td">;
// RANK COLUMN WOULD GO HERE
echo "<td>" . $rows->CurrentSales. "<td>";
// LAST YEAR'S RANK WOULD GO HERE
echo "<td>" . $rows->LastYrSales . "<td>";
echo "<td>" . ($rows->CurrentSales - $rows->LastYrSales)/$rows->LastYrSales) . "<td>";
echo "</tr>";
}
echo "</table>";
有没有好的方法使用数组来表示列?然后根据不同的值对数组进行排序?
另外,有没有人找到任何出色的方法来对列进行总计和平均并将其附加到表格中?
I'm working on generating a PHP/MySQL report that compares current and last year's sales data for a list of retail stores.
All of the data comes in fine from the SQL database. The sticking point is that the report needs to show how the stores are ranked this year, and what their ranking was last year.
Here's what the table should look like.
https://i.sstatic.net/trEsO.png
Here's the related part of my code.
$this->result = mysql_query($totalSalesQuery);
echo "<table>";
while($rows = mysql_fetch_object($this->result))
{
echo "<tr>";
echo "<td>" .$rows->store . "</td">;
// RANK COLUMN WOULD GO HERE
echo "<td>" . $rows->CurrentSales. "<td>";
// LAST YEAR'S RANK WOULD GO HERE
echo "<td>" . $rows->LastYrSales . "<td>";
echo "<td>" . ($rows->CurrentSales - $rows->LastYrSales)/$rows->LastYrSales) . "<td>";
echo "</tr>";
}
echo "</table>";
Is there a good way to use arrays to represent the columns? And then sort the arrays based on the different value?
Also, has anyone found any brilliant ways to total and average the columns and append that to the table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我肯定会在 SQL 方面这样做。
看看此讨论 关于如何在 MySQL 中进行排名
I would definitely do this on the SQL side of things.
Take a look at this discussion on how to do ranking in MySQL