Jump to content

Recommended Posts

Hello phpfreaks!,

 

I know the title is really confusing.

But let me explain. I need a little help here.

$queryreport = mysql_query("SELECT post_time_dif FROM response WHERE profile_id = '$id'");
     while($row = mysql_fetch_array($queryreport)){
          $post_time_dif = $row['post_time_dif'];
          $post_time_dif_tot += $post_time_dif;
     }

Basically what I want to do is add all values from post_time_dif and put the total in $post_time_dif_tot variable

Running the above code gives me an error

 

Notice: Undefined variable: post_time_dif_tot

 

Im relatively new @php so any help or idea would really be appreciated.

 

Thanks :)

Edited by blitz
Link to comment
https://forums.phpfreaks.com/topic/278463-adding-tables-while-mysql_fetch_array/
Share on other sites

$queryreport = mysql_query("SELECT post_time_dif FROM response WHERE profile_id = '$id'");
$post_time_dif_tot = 0;
     while($row = mysql_fetch_array($queryreport)){
          $post_time_dif = $row['post_time_dif'];
          $post_time_dif_tot += $post_time_dif;
     }

set zero value to $post_time_dif_tot variable above while loop or try above code or else you can disable notice errors from php.ini file

It was originally TIME, it got me in a lot of trouble so i changed it to VARCHAR. And it brought me a lot lot more trouble hahaha. Anyway I kinda got the work around already. I insert all record returns to an array and then using array_sum divide it by count of the array. and some more modifications based on my spagehetti code hehehe

 

Thanks everyone! :D

 

if you check your result, it is only using the leading field in the TIME value (the hours.)

 

you need to actually use a function that can perform math on a time value, generally by converting to a single base unit (seconds), performing the math, then converting back to a TIME value.

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.