Jump to content

foreach loop in an array


me1000

Recommended Posts


array('CourseName'=>'','number'=>'','Complete'=>'','expired'=>"",'inProgress'=>"") // make the first row blank, 

foreach ($arrCourses as $strKey => $strRow) {


// Total Enrolled
$strQuery = "";
$intEnrolled = $Database->db->MyQuery($strQuery);
$counter['1'] = $counter['1'] + $intEnrolled;


// Completed
$strQuery = "";
$intCompleted = $Database->db->MyQuery($strQuery);
$counter['2'] = $counter['2'] + $intCompleted;

// Expired without Completing
$strQuery = "";
$intExpired = $Database->db->MyQuery($strQuery);
$counter['3'] = $counter['3'] + $intExpired;

// In Progress
$strQuery = "";
$intProgress = $Database->db->MyQuery($strQuery);
$counter['4'] = $counter['4'] + $intProgress;

,array('CourseName'=>$strRow['series'] ." ". $strRow['number'] ." (". $strRow['odid'].")",'number'=>$intEnrolled,'Complete'=>$intCompleted,'expired'=>$intExpired,'inProgress'=>$intProgress)

}

,array('CourseName'=>"TOTAL",'number'=>$counter['1'],'Complete'=>$counter['2'],'expired'=>$counter['3'],'inProgress'=>$counter['4'])


);

 

So basically I need the foreach loop to fill out the array, but from the php error im getting back Im going to guess that PHP doesnt let you do that.

 

So is there a way I can?

 

Thanks,

 

 

EDIT: By the way, I removed most of the queries prior to post because it is pointless to post them,

but there error im getting is

 

unexpected T_FOREACH, expecting ')'

so I know the problem is the loop!

Link to comment
https://forums.phpfreaks.com/topic/94848-foreach-loop-in-an-array/
Share on other sites

Your missing a semi colon

 

 

array('CourseName'=>'','number'=>'','Complete'=>'','expired'=>"",'inProgress'=>"") // make the first row blank, 

 

needs to be

 

array('CourseName'=>'','number'=>'','Complete'=>'','expired'=>"",'inProgress'=>""); // make the first row blank, 

 

Also you haven't set the array to a variable therefore this is doing nothing at all!

 

Regards

Liam

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.