gpt4 book ai didi

php - 在两个不同的 while 循环中添加数字

转载 作者:行者123 更新时间:2023-11-30 22:23:49 25 4
gpt4 key购买 nike

我在两个不同的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com