1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

php math's functions help

Discussion in 'PHP' started by ianhaney, Jul 11, 2013.

  1. #1

    I need some help with php math functions

    I have added a php order form to my website at the following


    I have added a total deposit to pay now field

    Two issues, one is I want the total to be divided into 2 and then that figure displayed in the total deposit to pay now input field

    Second issue is after filling the details and clicking submit, I have made extra text saying total deposit to pay now, I want that to display the total price divided by 2 and then the paypal button to know that number divided into 2 and taken through to PayPal

    At the moment the paypal button is just taking the total price and going through to PayPal

    I can send over php files if that is possible through PM or by email if anyone wants to email me at

    Thank you in advance

    Kind regards

    ianhaney, Jul 11, 2013 IP
  2. sarahk

    sarahk iTamer Staff

    Likes Received:
    Best Answers:
    Trophy Points:
    Sounds pretty straightforward... how about you post the relevant bits of code that are causing trouble and wrap them in [ php] bbcode.
    sarahk, Jul 11, 2013 IP
    ColorWP.com likes this.
  3. ianhaney

    ianhaney Greenhorn

    Likes Received:
    Best Answers:
    Trophy Points:
    Hi sarahk

    Thank you for the reply

    I have posted below the relevant coding

    If need be, I can zip the file and attach it

        // total row
            $tbl->addCell( 'Total: ', 'total', 'data', array('colspan'=>3) );
            $tbl->addCell( $frm->addInput('text', 'total', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') ) );
                    // total deposit row
            $tbl->addCell( 'Total deposit to pay now: ', 'totaldeposit', 'data', array('colspan'=>3) );
            $tbl->addCell( $frm->addInput('text', 'totaldeposit', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') ) );
    Below is the paypal button code

    <form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="margin-top: 3%;">
        <input type="hidden" name="cmd" value="_xclick" />
        <input type="hidden" name="business" value="$paypal_email" />
        <input type="hidden" name="amount" value="$totaldeposit" /> - see where I added deposit to the word total, it was just total before
        <input type="hidden" name="currency_code" value="GBP">
        <input type="hidden" name="item_name" value="$desc" />
        <input type="hidden" name="custom" value="$custom" />
        <input type="hidden" name="return" value="$return_url" />
        <input type="hidden" name="cancel_return" value="$cancel_url" />
        <input type="image" name="submit "border="0"
            alt="PayPal - The safer, easier way to pay online" />
    Code (markup):
    Bit more PHP below

    if ( $str === '' ) {
            $str = '<p>You didn\'t order anything.</p>';
        } else {
            $str = '<h2 class="ordertitle">Your Order:</h2>' . $str . '<br>' .'<p>Total: £' .  number_format($total, 2) . '<br><br>' . 'Total Deposit to pay now: £' . number_format($total, 2) . '</p>' . getPayPalBtn($totaldeposit);
        return $str;
    Hope that all helps

    ianhaney, Jul 11, 2013 IP
  4. scriptjerk

    scriptjerk Active Member

    Likes Received:
    Best Answers:
    Trophy Points:
    Can you not access that $total variable and just do this before you call the button?

    $totaldeposit = $total/2;
    scriptjerk, Jul 13, 2013 IP