Jump to content

Adding DB Values


kannuk

Recommended Posts

Hey! How've you been? This should be simple but I can't make it work. I have a few database values from a user entry. The page queries the database and I can print them no problem. I want to add them and display the total of these values. I've tried about two dozen ways of doing and I just can't get them to add. Where I have "fee_total" I want it to be the sum of the values "fee+upgrade7+tax". This is the snippet of what I'm working on. I won't attach any of what I have tried because, well, there are too many attempts and nothing worked :(

 

    $sql = ("SELECT * FROM Teamregister WHERE pkSoloregisterID=$pkSoloregisterID");

    $query = mysql_query($sql);

    $result = mysql_query($sql);

    $myrow = mysql_fetch_array($result);

 

    printf ('<form action="https://www.mysite.com/cgi-bin/webscr" method="post">

<p>Your registration fee is <strong>$%s</strong>.</p>', $myrow['total_fee']);

echo ("<input type='hidden' name='item_name_1' value='Registration Fee'>");

printf ('<input type="hidden" name="amount_1" value="%s">', $myrow['total_fee']);

echo ("<br /><div align='center'>

<input type='submit'' value='Pay Online'>

</form>');

 

Make sense? Like I said, the values are already there but the math isn't happening. To check I tried using individual DB values instead of "total_fee" and the numbers show up. Just cannot get them to add.

Link to comment
Share on other sites

you're calling the mysql_query twice...


    $sql = ("SELECT (fee + upgrade + tax) AS theTotal, * FROM Teamregister WHERE pkSoloregisterID=$pkSoloregisterID");
    $result = mysql_query($sql);
    $myrow = mysql_fetch_array($result);

echo $myrow['theTotal'];

 

Link to comment
Share on other sites

Thanks for the reply, Joel24. After some more messing around, this is what I ended up doing and it also works.

 

$sql = ("SELECT * FROM Teamregister WHERE pkSoloregisterID=$pkSoloregisterID");

    $query = mysql_query($sql);

    $result = mysql_query($sql);

    $myrow = mysql_fetch_array($result);

    $total = floatval( $myrow['fee'] ) + floatval( $myrow['upgrade7'] ) + floatval( $myrow['tax'] );

 

printf ('<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

<p>Your registration fee is <strong>$%s</strong>.</p>', number_format( $total, 2 ));

echo ("<input type='hidden' name='item_name_1' value='Registration fee'>");

printf ('<input type="hidden" name="amount_1" value="%s">', number_format( $total, 2 ));

echo ("<div align='center'>

<input type='submit'' value='Pay Online'></div>

</form>

 

I appreciate you taking the time to respond!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.