how to calculate quantity and price in php

Solutions on MaxInterview for how to calculate quantity and price in php by the best coders in the world

showing results for - "how to calculate quantity and price in php"
Tim
07 Sep 2018
11   <!doctype html>
22   <html lang="en">
33   <head>
44      <meta charset="utf-8">
55      <title>Product Cost Calculator</
6    title>
76      <style type="text/css">
87         .number { font-weight: bold; }
98      </style>
109   </head>
1110  <body>
1211  <?php // Script 4.2 - handle_calc.php
1312  /* This script takes values from
14    calculator.html and performs
1513  total cost and monthly payment
16    calculations. */
1714
1815  // Address error handling, if you want.
1916
2017  // Get the values from the $_POST array:
2118  $price = $_POST['price'];
2219  $quantity = $_POST['quantity'];
2320  $discount = $_POST['discount'];
2421  $tax = $_POST['tax'];
2522  $shipping = $_POST['shipping'];
2623  $payments = $_POST['payments'];
2724
2825  // Calculate the total:
2926  $total = $price * $quantity;
3027  $total = $total + $shipping;
3128  $total = $total - $discount;
3229
3330  // Determine the tax rate:
3431  $taxrate = $tax / 100;
3532  $taxrate = $taxrate + 1;
3633
3734  // Factor in the tax rate:
3835  $total = $total * $taxrate;
3936
4037  // Calculate the monthly payments:
4138  $monthly = $total / $payments;
4239
4340  // Print out the results:
4441  print "<p>You have selected to
45    purchase:<br>
4642  <span class=\"number\">$quantity</
47    span> widget(s) at <br>
4843  $<span class=\"number\">$price</span>
49    price each plus a <br>
5044  $<span class=\"number\">$shipping</
51    span> shipping cost and a <br>
5245  <span class=\"number\">$tax</span>
53    percent tax rate.<br>
5446  After your $<span
55    class=\"number\">$discount</span>
56    discount, the total cost is
5747  $<span class=\"number\">$total</
58    span>.<br>
5948  Divided over <span
60    class=\"number\">$payments</span>
61    monthly payments, that would be
62    $<span class=\"number\">$monthly</
63    span> each.</p>";
6449
6550  ?>
6651  </body>
6752  </html>
Enoch
15 May 2019
1<?php
2	$pro_id = $_COOKIE['product_id'];   
3	$pro_id = explode(',', $pro_id);
4	$qua = 1;
5	foreach ($pro_id as $val) {
6		$ans = "SELECT * FROM wm_products WHERE pro_id='$val'";
7		$result = $conn->query($ans);
8		while($row = $result->fetch_assoc()){
9		?>
10			<tr class="cart_item">
11				<td>
12					<a href="single-product.html"><img src="products_images/<?php echo $row['pro_img']; ?>" alt="" width="180" height="180"></a>
13				</td>
14				<td>
15					<a href="single-product.html"><?php echo $row['pro_name']; ?></a>
16				</td>
17				<td>
18					<span class="amount">Rs. <?php echo $row['pro_price']; ?></span>
19				</td>
20				<td>
21					<div class="quantity buttons_added">
22					<form action="" method="post">
23						<input type="submit" class="minus" name="minus" value="-">				
24						<input type="text" size="4" class="input-text qty text" title="Qty" value="<?php echo $qua;?>" name="" max="29" min="0" step="1" >
25						<input type="submit" class="plus" name="plus" value="+">
26					</form>					
27					</div>
28				</td>
29				<td>
30					<span class="amount">Rs. <?php echo number_format($row['pro_price'] * $qua); ?></span>
31				</td>
32				<td>
33					<a class="remove remove_cart" href="#" dataid="<?php echo $row['pro_id']; ?>">×</a>
34				</td>
35			</tr>
36		<?php 
37		}                                   
38	}
39?>