【问题标题】:MySQL rank if empty show blank pageMySQL rank 如果为空则显示空白页
【发布时间】:2018-07-07 02:18:27
【问题描述】:

我有一个查询要按天显示前 5 名卖家,如果我想在工作日查看该页面,它可以工作,因为我在今天的这个日期之前的表格中有项目,但是如果我在星期天查看该页面,我得到一个完整的白页

有没有办法不得到这个白页?

这是卖家排名前 5 位 3 的示例

PHP

$datum=date('Y-m-d');

MYSQL

$tredje= mysqli_query($datacenter, "
SELECT vendedor, total, 
CASE WHEN @l=total THEN @r 
ELSE @r:=@r+1 END as rank,
  @l:=total FROM (select vendedor, 
sum(ventatotal) as total 
from ventas WHERE `fecha` = '$datum' 
group by vendedor 
order by total desc 
LIMIT 7 OFFSET 2 
) totals, (SELECT @r:=0, @l:=NULL) rank;");

要显示的 PHP

while($dentredje = mysqli_fetch_assoc($tredje))
{
?>
<?php echo number_format($dentredje['total'],0,',','.'); ?>

这是查询

【问题讨论】:

  • 您可能想要启用 PHP error_reporting,这可能是查询或其他问题严重失败并停止所有 PHP 执行,然后呈现一个空页面。
  • 只有当我在没有保存项目的一天(非工作日)查询时才会发生这种情况,因为没有销售
  • 如果没有匹配项,您希望看到什么?
  • 0 应该不错
  • 一个数字 cero 表示没有销售

标签: php html css mysql database


【解决方案1】:
if($dentredje)
{
    while($dentredje = mysqli_fetch_assoc($tredje))
    {
        echo number_format($dentredje['total'],0,',','.');
    }
}
else
{
    echo "your Sunday message here.";
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-19
    • 1970-01-01
    • 2022-08-18
    • 1970-01-01
    • 2019-12-09
    • 2016-05-29
    • 1970-01-01
    相关资源
    最近更新 更多