kannuk Posted November 14, 2011 Share Posted November 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/251098-adding-db-values/ Share on other sites More sharing options...
joel24 Posted November 14, 2011 Share Posted November 14, 2011 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']; Quote Link to comment https://forums.phpfreaks.com/topic/251098-adding-db-values/#findComment-1287928 Share on other sites More sharing options...
kannuk Posted November 14, 2011 Author Share Posted November 14, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/251098-adding-db-values/#findComment-1288004 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.