Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Deduct 15% Discount of Total

    How can I get the total to automatically deduct 15%? Here's the code base:

    PHP Code:
    <table width="694" border="0" cellspacing="0" cellpadding="5" align="center">
                   
                    <tr >
                      <td width="163">Product</td>
                      <td width="134" nowrap="nowrap">Payment Method </td>
                      <td width="46">Price</td>
                      <td width="56">Qty</td>
                      <td width="48">Total</td>
                      <td width="59">Remove</td>
                    </tr>
                    <?php
       
    for ( $counter 1$counter <= $_SESSION["cnt"]; $counter += 1)
       {   
          if((
    $counter%2)==0)   
          {
          
    ?>
                    <tr>
                      <?php
          
    }
          
    ?>
                      <td><?php echo($_SESSION["title".$counter]); ?></td>
                      <td ><?php echo($_SESSION["paymentmethod".$counter]); ?></td>
                      <td >$<?php echo($_SESSION["price".$counter]); ?></td>
                      <td><?php echo($_SESSION["qty".$counter]); ?></td>
                      <td>$<?php echo($_SESSION["total".$counter]); ?></td>
                      <td>
                      <input name="button" type="button" class="red" onclick="remove('<?php echo($counter); ?>')" value=" X"/>                </td>
                    </tr>
                    <?php
       
    }
       
    ?>
                    <tr>
                      <td colspan="3" rowspan="3" >&nbsp;</td>
                      <td valign="middle">Sub Total:</td>
                      <td> $<?php echo($_SESSION["grandtotal"]); ?></td>
                      <td >&nbsp;</td>
                    </tr>
                    <tr>
                      <td valign="middle" nowrap="nowrap" >- Discount %:</td>
                      <td>15</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td ><div >Shipping:</div></td>
                      <td>$0</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td colspan="4" valign="middle">Grand Total:</td>
                      <td colspan="2" >$<?php
    function add($x,$y)
    {
    $total=$x+$y;
    return 
    $total;
    }

    echo  
    add($_SESSION["grandtotal"],0);
    ?>
                      </strong></td>
                    </tr>
                  </table>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    15% off is simply 85% of the cost. So multiply whichever total it is you are looking at (or maybe the price? I'm not sure which) by 0.85.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts
    How to do that please? I am NOT a php guru. I know how to multiply just not in PHP.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    $dDiscounted = $dWhateverPriceVariable * 0.85;
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    johnwboyd (03-08-2013)

  • #5
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    $dDiscounted = $dWhateverPriceVariable * 0.85;
    What to do with this in my code base? Sorry but I don't know where to put this or how to integrate it... I'm a PHP newbie. Thanks.

  • #6
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts
    ?........

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Well, you put it wherever it is you want it to show up. You'll need to modify the $dWhateverPriceVariable to match the one you are looking at. Although I cannot be sure its the one, I would be it to be $_SESSION['grandtotal'].
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #8
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts
    I got it to work with this:

    PHP Code:
    <?php $reducedTotal $_SESSION["grandtotal"] * .85?>
                      $<?php echo $reducedTotal?>

    But somehow the reducedTotal is not writing to the email. This is the code I put in the php mail file:

    PHP Code:
    '.$_SESSION["reducedTotal"].' 
    Can someone please help me with what may be wrong as to why it's not sending this variable (discount) in the email?
    Last edited by johnwboyd; 03-10-2013 at 08:14 AM.

  • #9
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts
    ?.......

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Did you construct a $_SESSION variable for reducedTotal? Just creating the $reducedTotal doesn't create a session variable, to do that you need to use $_SESSION['reducedTotal'] = $reducedTotal;.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    johnwboyd (03-11-2013)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •