繁体   English   中英

php一个sql查询和一个php变量

[英]php sum of an sql query and an php variable

嘿伙计们,我想要一个mysql查询和一个php变量的总和。 有这个功能吗? 这是我试过的:

$result3 = mysql_query($sql3);
                while ($resultarray3 = mysql_fetch_array($result3)){
                $Ergebnis = $Menge + $resultarray['Bestand'];
                echo $Ergebnis;
                }

谁可以帮我这个事?

编辑:我想要一个php变量和一个mysql查询的总和不是两个sql表!!!!

$menge = '';
$result3 = mysql_query($sql3);
while ($resultarray3 = mysql_fetch_array($result3)){
  $menge = $menge + $resultarray3['Bestand'];
}
// result => $menge

如果只有一行,则不需要.=

$result3 = mysql_query($sql3);
            while ($resultarray3 = mysql_fetch_array($result3)){
            $Ergebnis .= $Menge + $resultarray3['Bestand'];//notice the change on this line
            echo $Ergebnis;
            }

显示结果的查询包含SUM(列),因此您可以使用:

$sql3 = "SELECT bestand, SUM(bestand) as menge FROM database GROUP BY bestand";

然后在PHP中

$result3 = mysql_query($sql3);
while ($resultarray3 = mysql_fetch_array($result3)){
    echo $resultarray['bestand'] . ' = ' . $resultarray['menge'];
}

你定义$resultarray3然后你使用$resultarray而没有三个。

$Ergebnis = $Menge + $resultarray3['Bestand'];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM