我在两个不同的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;
我想完全做这件事,但结果不合适。请帮忙。
答案 0 :(得分:0)
你可以试试这个 -
$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;
答案 1 :(得分:0)
你可能想这样做:
DECLARE
v_list sys.Odcinumberlist := sys.Odcinumberlist( 1, 2, 3, 4 );
v_member_found char(3);
BEGIN
FOR i IN 1..v_list.COUNT LOOP
dbms_output.put_line( v_list(i) );
END LOOP;
begin
select 'yes' into v_member_found
from table(v_list)
where column_value = 1;
exception
when no_data_found
then v_member_found := 'no';
end;
dbms_output.put_line(v_member_found);
END;
答案 2 :(得分:0)
你可以试试这个:
$a = 0;
$b = 0;
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;