Jump to content

Adding two columns of different rows


Recommended Posts

please help me out...

 

How to get this (img.jpg) type of result.

 

I have 4 columns namely, ID, NEW, AMOUNT, TOTAL.

please see my image attachment to understand easily.

 

for first row, TOTAL= AMOUNT,

for 2nd row, TOTAL=  AMOUNT(ROW1) + AMOUNT(ROW2) OR AMOUNT(ROW2) + TOTAL(ROW1),

for 3rd row, TOTAL=  AMOUNT(ROW1) + AMOUNT(ROW2)+AMOUNT(ROW3) OR AMOUNT(ROW3) + TOTAL(ROW2).

and so on...

means loop will be upto the end of table.

 

I hope u understood my doubt.

 

please help me out...

 

THANK YOU.

post-164592-0-01206100-1375787587_thumb.jpg

Edited by Pradeep_Chinna
Link to comment
Share on other sites

As you loop through the result set, add the amount for the current row to a total variable and save that variable to the row. eg:

$total = 0;
$allRows = array();
while ($row=$result->fetch()){
   $total += $row['amount'];
   $row['total'] = $total;

   $allRows[] = $row;
}
Then when you output the data in your table you'll have the total field in each row to output.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.