156418 Posted October 10, 2006 Share Posted October 10, 2006 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 pageIs that possible, or will I need to add it into the Database and pull the figures back out? Quote Link to comment https://forums.phpfreaks.com/topic/23583-multiply-some-numbers/ Share on other sites More sharing options...
Daniel0 Posted October 10, 2006 Share Posted October 10, 2006 Multiply: [code]$var1 * $var2[/code]Addition: [code]$var1 + $var2[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23583-multiply-some-numbers/#findComment-107063 Share on other sites More sharing options...
156418 Posted October 10, 2006 Author Share Posted October 10, 2006 Thanks, It looks simple enough, but how do i get it to display the output rather than the command[code]<?php echo $_POST['$AdultQuantity * $APrice']; ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23583-multiply-some-numbers/#findComment-107067 Share on other sites More sharing options...
akitchin Posted October 10, 2006 Share Posted October 10, 2006 [code]<?php echo $_POST['AdultQuantity'] * $_POST['APrice']; ?>[/code]each $_POST value is its own variable. Quote Link to comment https://forums.phpfreaks.com/topic/23583-multiply-some-numbers/#findComment-107074 Share on other sites More sharing options...
156418 Posted October 10, 2006 Author Share Posted October 10, 2006 Ah, I see. Would I be right in assuming that I wont be able to add the three totals together without first posting the results? Quote Link to comment https://forums.phpfreaks.com/topic/23583-multiply-some-numbers/#findComment-107088 Share on other sites More sharing options...
allydm Posted October 10, 2006 Share Posted October 10, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/23583-multiply-some-numbers/#findComment-107092 Share on other sites More sharing options...
156418 Posted October 10, 2006 Author Share Posted October 10, 2006 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">£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">£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">£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! Quote Link to comment https://forums.phpfreaks.com/topic/23583-multiply-some-numbers/#findComment-107126 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.