Forum Moderators: coopster

Message Too Old, No Replies

loop, add,?

         

ayushchd

6:42 pm on May 9, 2007 (gmt 0)

10+ Year Member



i have this bit of code :

while ($row = mysql_fetch_assoc($result)) {

echo $row['pmt'];

}

Now what i want to do is that add all the $row['pmt'], store the added value in a variable and display......

jatar_k

6:49 pm on May 9, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member




$mytotal = 0;
while ($row = mysql_fetch_assoc($result)) {
$mytotal .= $row['pmt'];
}
echo $mytotal;

ayushchd

7:31 pm on May 9, 2007 (gmt 0)

10+ Year Member



Thanks jatar_k,

But cud u tell me why did u use .=?

Wht is the dot there for?

jatar_k

7:45 pm on May 9, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the dot is the concatenation operator [php.net] which is a mistake, since you said 'add'

it should be

$mytotal = 0;
while ($row = mysql_fetch_assoc($result)) {
$mytotal += $row['pmt'];
}
echo $mytotal;

sorry about that