Jump to content

Adding in while loop


max_w1

Recommended Posts

hello, i have created a table that desplays perticulars, price per person and number of people. the fees is then calculated by multiplying price per person with number of people. till now everything is good. but the problem is when i try to calculate the total fees.

here is an example to explain you better:

PerticularsPrice Per PersonNumber of peopleAmount

something101001000

something else201002000

Total 3000

 

 

$pert_query = mysql_query ("SELECT * FROM `perticulars` WHERE `invoice` =$invoice") or die(mysql_error());
$i = 1;
$sum = 0 + $_SESSION['sum'];
 while($perticulars = mysql_fetch_array($pert_query, MYSQL_ASSOC)) {
?>
<tr>
      <td style="border-collapse: collapse"><div align="center"><?php echo $i;
  $i++; 
   ?></div></td>
      <td style="border-collapse: collapse"><div align="center"><?php echo $perticulars['perticulars']; ?></div></td>
      <td style="border-collapse: collapse"><div align="center"><?php echo $perticulars['ppc']; ?></div></td>
      <td style="border-collapse: collapse"><div align="center"><?php echo $perticulars['nop']; ?></div></td>
      <td style="border-collapse: collapse"><div align="center">
        <?php $amount = $perticulars['ppc'] * $perticulars['nop']; echo $amount; $_SESSION['sum'] = $sum+$amount;?>
      </div></td>
    </tr><?php 
} ?>
    <tr>
      <td colspan="4" style="border-collapse: collapse"><div align="center">Total</div></td>
      <td style="border-collapse: collapse"><div align="center"><?php echo $sum; ?></div></td>
    </tr>
  </table>

 

From the above code you can see that i am getting the amount form $amount = $perticulars['ppc'] * $perticulars['nop'];

by this each row has its own amount which i got by multiplying the data from mysql.

the problem is how do i find out the Total. i know i am suppose to add up $amount but how?

i even tired using sessions to store the amount and add the new amount to get total but the problem in using sessions is it messes up my next page, no using session is a very bad idea.

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.