Jump to content

adding tables while mysql_fetch_array


blitz

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 :)

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.

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.