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
https://forums.phpfreaks.com/topic/251098-adding-db-values/
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
https://forums.phpfreaks.com/topic/251098-adding-db-values/#findComment-1287928
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
https://forums.phpfreaks.com/topic/251098-adding-db-values/#findComment-1288004
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.