% Discount of total

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

johnwboyd
New php-forum User
New php-forum User
Posts: 4
Joined: Thu Mar 07, 2013 2:34 am

% Discount of total

Postby johnwboyd » Thu Mar 07, 2013 2:52 am

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

Code: Select all

<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>

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: % Discount of total

Postby seandisanti » Thu Mar 07, 2013 12:17 pm

Code: Select all

$total*=.85;

johnwboyd
New php-forum User
New php-forum User
Posts: 4
Joined: Thu Mar 07, 2013 2:34 am

Re: % Discount of total

Postby johnwboyd » Fri Mar 08, 2013 10:20 am

Thanks but if I knew how to integrate I would probably not be here. Can you please give me the ENTIRE tag?

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: % Discount of total

Postby seandisanti » Fri Mar 08, 2013 10:32 am

Just assign to a new variable like...

Code: Select all


$reducedTotal 
$total .85;
 

and then you can drop it into your html wherever you want by putting:

Code: Select all

<?php echo $reducedTotal; ?>


play around with it a little bit and you'll get it.

johnwboyd
New php-forum User
New php-forum User
Posts: 4
Joined: Thu Mar 07, 2013 2:34 am

Re: % Discount of total

Postby johnwboyd » Sat Mar 09, 2013 9:37 am

I got it to work with this:

Code: Select all

<?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:

Code: Select all

'.$_SESSION["reducedTotal"].' 

johnwboyd
New php-forum User
New php-forum User
Posts: 4
Joined: Thu Mar 07, 2013 2:34 am

Re: % Discount of total

Postby johnwboyd » Sat Mar 09, 2013 11:14 pm

Can someone please help me with what may be wrong as to why it's not sending this variable (discount) in the email?

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: % Discount of total

Postby seandisanti » Mon Mar 11, 2013 7:25 am

very close; you're assigning the reduced total to $reducedTotal, not $_SESSION['reducedTotal'] change either of those to be the same as the other and you should be all set.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest

cron