我在两个不同的 while 循环中从数据库中获取数据,我想在循环外添加它们之间的变量。示例:
while($cash_fetch = mysql_fetch_array($cash_qur))
{
$a = 500; //suppose I am fetching from database
}
while($card_fetch = mysql_fetch_array($card_qur))
{
$b = 1000; //suppose I am fetching from database
}
$total = $a+$b;
echo $total;
我确实想做这件事,但得到的结果不合适。请帮忙。
最佳答案
你可以试试这个 -
$a = $b = 0; // set to 0 by default
while($cash_fetch = mysql_fetch_array($cash_qur))
{
$a += 500; //Increment
}
while($card_fetch = mysql_fetch_array($card_qur))
{
$b += 1000; //Increment
}
$total = $a + $b;
echo $total;
关于php - 在两个不同的 while 循环中添加数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35909200/