scmeeker Posted July 12, 2010 Share Posted July 12, 2010 I'm having trouble getting the $item_fee variable to produce a result. When echoing, it doesn't produce anything. I would like it to add all the values under the "item_fee" column for this month and for the particular user. I would appreciate any feedback on this. I've tried it several ways with no luck. Here's the code I've written for it: $get_item_sql = "SELECT SUM(item_fee), date, username FROM product WHERE MONTH(date) = MONTH(CURDATE()) AND username = '".$_GET["username"]."'"; $get_item_res = mysqli_query($mysqli, $get_item_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($get_item_res) < 1) { //invalid item $display_block .= "<p><em>Invalid item selection.</em></p>"; } else { //valid item, get info while ($item_info = mysqli_fetch_array($get_item_res)) { $item_fee = $item_info['item_fee']; $image_fees = $item_fee * .20; Then I echo the $item_fee it to a page but have nothing come up. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/207468-problem-producing-result/ Share on other sites More sharing options...
Pikachu2000 Posted July 12, 2010 Share Posted July 12, 2010 The simplest thing to do is select the value AS something in the query, then reference that when displaying the results. Look at how I changed the query to SELECT SUM() AS fee, then changed the variable assignment later to $item_fee = $item_info['fee']. $get_item_sql = "SELECT SUM(item_fee) AS fee, date, username FROM product WHERE MONTH(date) = MONTH(CURDATE()) AND username = '".$_GET["username"]."'"; $get_item_res = mysqli_query($mysqli, $get_item_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($get_item_res) < 1) { //invalid item $display_block .= "<p><em>Invalid item selection.</em></p>"; } else { //valid item, get info while ($item_info = mysqli_fetch_array($get_item_res)) { $item_fee = $item_info['fee']; $image_fees = $item_fee * .20; Quote Link to comment https://forums.phpfreaks.com/topic/207468-problem-producing-result/#findComment-1084685 Share on other sites More sharing options...
scmeeker Posted July 12, 2010 Author Share Posted July 12, 2010 Thanks SO much...it works perfect now. I spent hours yesterday trying to solve that between research and trial. Quote Link to comment https://forums.phpfreaks.com/topic/207468-problem-producing-result/#findComment-1084923 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.