Answers for "how to calculate quantity and price in php"

PHP
0

how to calculate quantity and price in php

1   <!doctype html>
2   <html lang="en">
3   <head>
4      <meta charset="utf-8">
5      <title>Product Cost Calculator</
    title>
6      <style type="text/css">
7         .number { font-weight: bold; }
8      </style>
9   </head>
10  <body>
11  <?php // Script 4.2 - handle_calc.php
12  /* This script takes values from
    calculator.html and performs
13  total cost and monthly payment
    calculations. */
14
15  // Address error handling, if you want.
16
17  // Get the values from the $_POST array:
18  $price = $_POST['price'];
19  $quantity = $_POST['quantity'];
20  $discount = $_POST['discount'];
21  $tax = $_POST['tax'];
22  $shipping = $_POST['shipping'];
23  $payments = $_POST['payments'];
24
25  // Calculate the total:
26  $total = $price * $quantity;
27  $total = $total + $shipping;
28  $total = $total - $discount;
29
30  // Determine the tax rate:
31  $taxrate = $tax / 100;
32  $taxrate = $taxrate + 1;
33
34  // Factor in the tax rate:
35  $total = $total * $taxrate;
36
37  // Calculate the monthly payments:
38  $monthly = $total / $payments;
39
40  // Print out the results:
41  print "<p>You have selected to
    purchase:<br>
42  <span class=\"number\">$quantity</
    span> widget(s) at <br>
43  $<span class=\"number\">$price</span>
    price each plus a <br>
44  $<span class=\"number\">$shipping</
    span> shipping cost and a <br>
45  <span class=\"number\">$tax</span>
    percent tax rate.<br>
46  After your $<span
    class=\"number\">$discount</span>
    discount, the total cost is
47  $<span class=\"number\">$total</
    span>.<br>
48  Divided over <span
    class=\"number\">$payments</span>
    monthly payments, that would be
    $<span class=\"number\">$monthly</
    span> each.</p>";
49
50  ?>
51  </body>
52  </html>
Posted by: Guest on September-16-2020
0

how to update quantity to calculate total price from price in php

<?php
	$pro_id = $_COOKIE['product_id'];   
	$pro_id = explode(',', $pro_id);
	$qua = 1;
	foreach ($pro_id as $val) {
		$ans = "SELECT * FROM wm_products WHERE pro_id='$val'";
		$result = $conn->query($ans);
		while($row = $result->fetch_assoc()){
		?>
			<tr class="cart_item">
				<td>
					<a href="single-product.html"><img src="products_images/<?php echo $row['pro_img']; ?>" alt="" width="180" height="180"></a>
				</td>
				<td>
					<a href="single-product.html"><?php echo $row['pro_name']; ?></a>
				</td>
				<td>
					<span class="amount">Rs. <?php echo $row['pro_price']; ?></span>
				</td>
				<td>
					<div class="quantity buttons_added">
					<form action="" method="post">
						<input type="submit" class="minus" name="minus" value="-">				
						<input type="text" size="4" class="input-text qty text" title="Qty" value="<?php echo $qua;?>" name="" max="29" min="0" step="1" >
						<input type="submit" class="plus" name="plus" value="+">
					</form>					
					</div>
				</td>
				<td>
					<span class="amount">Rs. <?php echo number_format($row['pro_price'] * $qua); ?></span>
				</td>
				<td>
					<a class="remove remove_cart" href="#" dataid="<?php echo $row['pro_id']; ?>">×</a>
				</td>
			</tr>
		<?php 
		}                                   
	}
?>
Posted by: Guest on May-27-2020

Code answers related to "how to calculate quantity and price in php"

Browse Popular Code Answers by Language