Jump to content

Reading arrays in function


mausie

Recommended Posts

Hi all,

I'm reading out a database to get the total worked time of people on a month. I got this code I use on every single table(alot):

[code]$arraycount = -1;
$timetotal = 0;

foreach ( $query['DATUM'] as $date)
{
   
    $arraycount = $arraycount + 1;         
           
      $sub = substr($date,3,2);
   
      if ($sub == '01' && $query['TIMECLASSID'][$arraycount] == 3)
      {
      $timetotal = $timetotal +  $query['CALCTIME'][$arraycount];
      }
 
}

print $timetotal; [/code]
This works fine,even tho I thought it would be much easier to make an function for this because it's alot of code doing this for like 30 tables. so I made:
[code]
function monthtotal($mon,$timeclass)
{
$arraycount = -1;
$timetotal = 0;
 
foreach ( $query['DATUM'] as $date)
{
   
    $arraycount = $arraycount + 1;         
           
      $sub = substr($date,3,2);
   
      if ($sub == $mon && $query['TIMECLASSID'][$arraycount] == $timeclass)
      {
      $timetotal = $timetotal +  $query['CALCTIME'][$arraycount];
      }
 
}
return $timetotal;
}[/code]

But i get Invalid argument in foreach() everytime I use this function. Because, of what I think it can't read the $query. But why is this?
Could any1 help me? That would be great

Maurice
Link to comment
Share on other sites

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.