gpt4 book ai didi

php - 在 PHP 中显示来自 MySQL 的结果旁边的图像?

转载 作者:行者123 更新时间:2023-11-29 03:43:46 25 4
gpt4 key购买 nike

我正在使用 PHP 从 MySQL 数据库中提取一个表。

这大致是我正在使用的代码,显然我有更多的专栏,但这是代码的演示版本。

如您所见,代码按销售名称排序。现在我想要做的是,根据销售额在前十名卖家旁边显示一个小图标。因此,如果销售额是前十位数字之一,则它的名称旁边必须显示一个小图像。

这可以做到吗?

<?php
// Get all the data from the "sales" table
$result = mysql_query("SELECT * FROM sales ORDER BY SalesName") or die(mysql_error());
echo "<table border='1'>";
echo "<tr> <th>Sales Name</th> <th>Sales Count</th> </tr>";
while($row = mysql_fetch_array( $result )) {
echo "<tr><td>";
echo $row['SalesName'];
echo "</td><td>";
echo $row['SalesCount'];
echo "</td></tr>";
}
echo "</table>";
?>

最佳答案

是的,你可以做到:

    <?php
$item_no=1 // number of current items
// Get all the data from the "sales" table
$result = mysql_query("SELECT * FROM sales ORDER BY SalesCount desc SalesName ") or die(mysql_error());
echo "<table border='1'>";
echo "<tr> <th>Sales Name</th> <th>Sales Count</th> </tr>";

while($row = mysql_fetch_array( $result )) {
echo "<tr><td>";
if($item_no <= 10){
echo 'your image here';
$item_no++;
}

echo $row['SalesName'];
echo "</td><td>";
echo $row['SalesCount'];
echo "</td></tr>";
}
echo "</table>";
?>

关于php - 在 PHP 中显示来自 MySQL 的结果旁边的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9616953/

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