gpt4 book ai didi

php - 使用 php、sql、html/css 突出显示和平均/总销售额

转载 作者:太空宇宙 更新时间:2023-11-03 17:53:07 26 4
gpt4 key购买 nike

到目前为止我的代码是:

<body>

<table border='1' bordercolor="#000000">
<tr>

<th bgcolor="#000000"><font color="#ffffff">Product Id</font> </a></th>
<th bgcolor="#000000"><font color="#ffffff">Product Description</font> </a></th>
<th bgcolor="#000000"><font color="#ffffff">Store</font></th>
<th bgcolor="#000000"><font color="#ffffff">Qtr</font> </a></th>
<th bgcolor="#000000"><font color="#ffffff">Amount Sold</font> </a></th>
<th bgcolor="#000000"><font color="#ffffff">Cost</font></th>
<th bgcolor="#000000"><font color="#ffffff">Sales</font></th>

</tr>

<?php
$con=mysqli_connect("localhost:private","private","","private");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

if (isset($_GET["sortBy"]) )
$orderBy = $_GET["sortBy"];
else
$orderBy = "productId";

$sql = "select p.productId, p.name, ps.storeNumber, ps.qtr, ps.amountSold,
p.cost
from Products p
inner join ProductSold ps
on ps.productId = p.productId
where storeNumber = 100;";
$result = mysqli_query($con, $sql);


while($row = mysqli_fetch_array($result)) {
//print_r($row);
//echo "<hr />";
echo "<tr>";
echo "<td>" . $row['productId'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['storeNumber'] . "</td>";
echo "<td>" . $row['qtr'] . "</td>";
echo "<td>" . $row['amountSold'] . "</td>";
echo "<td>" . $row['cost'] . "</td>";
echo "<td>" . $sum_total = $row['cost'] * $row['amountSold'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>

我需要实现接下来的 2 个目标:

  1. 当销售额超过 4,000 时,以绿色突出显示销售额。
  2. 创建第二张表,显示总销售额、平均销售额和最低销售额。

|总销售额| $$$ ||平均销售额| $$$ ||最低销售额| $$$$ |

任何正确方向的帮助或指导将不胜感激,谢谢!

最佳答案

你的第一个查询的答案是

 if($row['cost'] * $row['amountSold']  > 4,000) {
echo "<td style="color:green">" . $sum_total = $row['cost'] * $row['amountSold'] . "</td>";
}else{
echo "<td>" . $sum_total = $row['cost'] * $row['amountSold'] . "</td>";
}

而且我认为第二个解决方案很简单,您可以尝试一下,因为您已经在自己的代码中完成了!

关于php - 使用 php、sql、html/css 突出显示和平均/总销售额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26857318/

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