dream752614590 2019-07-14 11:05
浏览 48
已采纳

是否有一个简单的函数来计算和输出PHP中的几个列值[关闭]

I have an application connected to a database. Now I want to add the values from several columns of several datasets together

I tried with the SUM()-Function but i don't know how to spend the values so that they are visible in the application.

I have no idea how to build the code smart.

it should be like this:

$sql = "SELECT SUM(column1)+(column2)";

echo $Sum of all columns and datasets.

  • 写回答

2条回答 默认 最新

  • duanjiaren8188 2019-07-14 11:30
    关注
    I have now following code:
    
     $sql = " SELECT
       SUM(ps_asyl_oberteil) as 'ps_asyl_oberteil',
       SUM(ps_asyl_unterteil) as 'ps_asyl_unterteil',
       SUM(ps_asyl_jacke) as 'ps_asyl_jacke',
       (SUM(ps_asyl_oberteil) + SUM(ps_asyl_unterteil) + SUM(ps_asyl_jacke)) as 'Total'
      FROM ps_asyl";
    
      Line 20: echo $result->Total;
    

    and I receive the following error message:

    Notice: Undefined variable: result in /opt/lampp/htdocs/lab/asylanten_detail.php on line 20

    Notice: Trying to get property 'Total' of non-object in /opt/lampp/htdocs/lab/asylanten_detail.php on line 20

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题