UPdate a variable depends on another variable changes

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

expertalert
New php-forum User
New php-forum User
Posts: 4
Joined: Sat Nov 17, 2012 3:48 am

UPdate a variable depends on another variable changes

Postby expertalert » Sun Apr 14, 2013 11:38 am

Hi
the question might be very confusing, but allow me to explain.

i have a loop like this ( its just an example) :

total_kw_pdu_A=0;
total_kw_pdu_B=0;
echo "Bellow is Individual Break down :"
while($row = mysql_fetch_assoc($rack_list))

{
..........................
.........................
echo "Pdua A: $outputA_kw"
echo "Pdu B:$$outputB_kw"
$total_kw_pdu_A=($outputA_kw + $total_kw_pdu_A);
$total_kw_pdu_B=($outputB_kw + $total_kw_pdu_B);


}
echo "Total K.W:"
echo "</br>";
echo $total_kw_pdu_A;
echo $total_kw_pdu_B;
-------------------------------------------------------------------------------------
So the value in $total_kw_pdu_A and $total_kw_pdu_B , is coming from the while loop.

and if i echo the value at last of the loop( as in the example code , it will give me to total , which is expected.

but my problem is : i need to show the output of $total_kw_pdu_A , Beginning of the page ,

Example the page will be like bellow :

Total K.W puda A: $total_kw_pdu_A
Total K.W puda B: $total_kw_pdu_B

Bellow is Individual Break down :
-------------------------------
----------------------------------
------------------------------


now what i am thinking is , by using javascript to update the value ..
So if i take an variable like , $new_total_kw_pdu_A , and if i can some how increase the couter as soon as the value of "$total_kw_pdu_A" in increase ...
Can this be one ??
or is there is any other way ??

Please advise ??

Thanks for your time.

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: UPdate a variable depends on another variable changes

Postby johnj » Sun Apr 14, 2013 7:41 pm

Do a display only after you complete the entire processing

swarups
New php-forum User
New php-forum User
Posts: 20
Joined: Tue Mar 06, 2012 11:05 pm

Re: UPdate a variable depends on another variable changes

Postby swarups » Mon Apr 15, 2013 1:11 am

Hi,

PHP always runs the first line and go the next. SO here you have to do two loop.

First: Do first loop to calculate calculate the total and display it.
Second: do another loop to daisplay Individual Break Down


Thanks
Swarup


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest