[英]php sum of an sql query and an php variable
Hey guys i want a sum of an mysql query and an php variable. 嘿伙计们,我想要一个mysql查询和一个php变量的总和。 Is there a function to do this?
有这个功能吗? Here is what i tried:
这是我试过的:
$result3 = mysql_query($sql3);
while ($resultarray3 = mysql_fetch_array($result3)){
$Ergebnis = $Menge + $resultarray['Bestand'];
echo $Ergebnis;
}
Can anyone help me on this? 谁可以帮我这个事?
Edit: I want a sum of an php variable and an mysql query not of two sql tables!!!! 编辑:我想要一个php变量和一个mysql查询的总和不是两个sql表!!!!
$menge = '';
$result3 = mysql_query($sql3);
while ($resultarray3 = mysql_fetch_array($result3)){
$menge = $menge + $resultarray3['Bestand'];
}
// result => $menge
If there is only one row you don't need the .=
如果只有一行,则不需要
.=
$result3 = mysql_query($sql3);
while ($resultarray3 = mysql_fetch_array($result3)){
$Ergebnis .= $Menge + $resultarray3['Bestand'];//notice the change on this line
echo $Ergebnis;
}
A query to show a result contains SUM(column), so you could use: 显示结果的查询包含SUM(列),因此您可以使用:
$sql3 = "SELECT bestand, SUM(bestand) as menge FROM database GROUP BY bestand";
And then in PHP 然后在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.