Jump to content

Multiply some numbers


156418

Recommended Posts

I have the following code, which is posted through from a form on a previous page:

[code]<?php echo $_POST['AdultQuantity']; ?> X <?php echo $_POST['ATicketType']; ?> @ £<?php echo $_POST['APrice']; ?> Each<br>
<?php echo $_POST['ChildQuantity']; ?> X <?php echo $_POST['CTicketType']; ?> @ £<?php echo $_POST['CPrice']; ?> Each<br>
<?php echo $_POST['PresentQuantity']; ?> X <?php echo $_POST['PTicketType']; ?> @ £<?php echo $_POST['PPrice']; ?>[/code]

what I'd like to do is multiple the Quantity by the Price for each of the three, and then total all three together in another part on the page

Is that possible, or will I need to add it into the Database and pull the figures back out?
Link to comment
Share on other sites

You could use Javascript to do it instantly on the page as it's entered.

Depending on how you 'define' the $_POST variables on the form you could have it do the calculations on loading the page (which i presume is a shopping basket or something). If you could use the code for the page that posts the data we may be able to give you some code.
Link to comment
Share on other sites

Hi, its similar to a shopping cart but not quite! It takes a Quantity and simply posts it to the next page, also there's some hidden text boxes which post the amount for each item (I know thats cheating, but I cant find any other way easily!

This is the page prior to that one, which posts the Quantity and price through

[code]<form method="POST" action="Stage6-Final.php">
<table width="70%" border="0">
  <tr>
    <td width="13%" bgcolor="#E6D0DD">Quantity</td>
    <td width="74%" bgcolor="#E6D0DD">Ticket Type </td>
    <td width="13%" bgcolor="#E6D0DD">Price</td>
  </tr>
  <tr>
    <td bgcolor="#E6D0D2"><div align="center">
      <input name="AdultQuantity" type="text" value="0" size="5">
    </div></td>
    <td bgcolor="#E6D0D2">Adult
    <input type="hidden" name="ATicketType" value="Adult" size="13" maxlength="20"></td>
    <td bgcolor="#E6D0D2">&pound;9
      <input type="hidden" name="APrice" value="9" size="10" maxlength="1">
</td>
  </tr>
  <tr>
    <td bgcolor="#E6D0D2"><div align="center">
      <input name="ChildQuantity" type="text" value="0" size="5">
    </div></td>
    <td bgcolor="#E6D0D2">Child
      <input type="hidden" name="CTicketType" value="Child" size="13" maxlength="20">
</td>
    <td bgcolor="#E6D0D2">&pound;6
      <input type="hidden" name="CPrice" value="6" size="10" maxlength="1">
</td>
  </tr>
  <tr>
    <td bgcolor="#E6D0D2"><div align="center">
      <input name="PresentQuantity" type="text" value="0" size="5">
    </div></td>
    <td bgcolor="#E6D0D2">Present
      <input type="hidden" name="PTicketType" value="Present" size="13" maxlength="20">
</td>
    <td bgcolor="#E6D0D2">&pound;3
      <input type="hidden" name="PPrice" value="3" size="10" maxlength="1"></p>
</td>
  </tr>
</table>


</form>[/code]

It also posts some other stuff, user details etc which is being pulled from the Database.

On the page that recieves it, I have the following:

[code]Tickets: </div>            </td>
            <td width="79%"><span class="style11"><?php echo $_POST['AdultQuantity']; ?> X <?php echo $_POST['ATicketType']; ?> @ £<?php echo $_POST['APrice']; ?> Each  <input type="input" name="AT" value="<?php echo $_POST['AdultQuantity'] * $_POST['APrice']; ?>" size="13" maxlength="20"><br>
  <?php echo $_POST['ChildQuantity']; ?> X <?php echo $_POST['CTicketType']; ?> @ £<?php echo $_POST['CPrice']; ?> Each<input type="input" name="CT" value="<?php echo $_POST['ChildQuantity'] * $_POST['CPrice']; ?>" size="13" maxlength="20"><br>
  <?php echo $_POST['PresentQuantity']; ?> X <?php echo $_POST['PTicketType']; ?> @ £<?php echo $_POST['PPrice']; ?> Each<input type="input" name="PT" value="<?php echo $_POST['PresentQuantity'] * $_POST['PPrice']; ?>" size="13" maxlength="20"><br></span></td>
          </tr>
          <tr>
            <td width="21%">
              <div align="right" class="style11 style12 style14">Total to Pay:  </div>            </td>
            <td width="79%"><span class="style11 style12 style14"><?php echo $_POST['AT'] * $_POST['PT']; ?></span></td>
          </tr>[/code]

Thats a cut down of it, the rest is just posting the rest of what was sent from the page before.
There's a lot of multiple posting of the same variables here as well.

No doubt there's a quicker way to do it all, adding and pulling back out from a DB, but I dunno where to begin on making that!
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.