You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP网站出现非数值警告问题求解(dashboard.php第15行)

问题解决方法

问题分析

仪表盘的警告来自两个核心问题:

  1. $totalRevenue初始化为空字符串,执行加法运算时会触发类型不匹配的警告
  2. 数据库orders表中不存在paid字段,代码中访问该未定义索引会抛出警告

修复步骤

  1. 修正变量初始类型
    将$totalRevenue = "";改为数字类型的初始值,避免类型转换警告:

    $totalRevenue = 0;
    
  2. 替换不存在的字段名
    根据orders表的实际结构,把代码中的$orderResult['paid']替换为表中存储订单金额的字段(比如grand_total):

    $totalRevenue += $orderResult['grand_total'];
    
  3. 可选优化:用SQL直接计算总收入
    可以省去循环计算的步骤,直接通过SQL查询得到结果,提升代码效率:

    $orderSql = "SELECT SUM(grand_total) AS totalRevenue FROM orders WHERE order_status = 1";
    $orderQuery = $connect->query($orderSql);
    $orderResult = $orderQuery->fetch_assoc();
    $totalRevenue = $orderResult['totalRevenue'] ?? 0;
    

内容的提问来源于stack exchange,提问作者Vivek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 22:57:26