Jump to content

Problem producing result


scmeeker

Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/207468-problem-producing-result/
Share on other sites

 

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;

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.