Jump to content

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;

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.