Jump to content

Archived

This topic is now archived and is closed to further replies.

Mobyforce1

Invalid argument supplied for foreach()

Recommended Posts

I created a new Module for my clan (Battlefield 2) stats. I have the moduel installed ok, but I get teh follwing error when tryign to view on the web page.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]

Warning: Invalid argument supplied for foreach() in /usr/local/psa/home/vhosts/fogofwar.us/httpdocs/modules/BF2_LeaderBoard/index.php on line 115


[/quote]


I rand a test page on the site and I am running PHP version 4.3.6. According to soem reading I need at least 4.1.0 so i guess I am good there.

Here is the link to teh site. This is our old one, but I wanted to test it here before moving it to the new one.

[a href=\"http://www.fogofwar.us/modules.php?name=BF2_LeaderBoard\" target=\"_blank\"]http://www.fogofwar.us/modules.php?name=BF2_LeaderBoard[/a]


Here is the part of the file that the error points to.
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]

<?php
line 115 foreach( $leadercache as $players ) { //cycle through each sub-array
if ( in_array($players['PID'], $squad) ) { //verify, else loop

//No one knows for sure what happens past Sergeant Major of the Corps
//I suspect they become 2nd Lieutenant after Sergeant Major of the Corps, and stay there. (until expansion?)
if ( ($players['RANK'] >= 11) ) {
$pcntDiff = number_format( 100, 2);
$newrank = "At ease soldier!";

[/quote]


Any ideas or help would be GREAT.......thanks in advance

Share this post


Link to post
Share on other sites
Is that line 115 before foreach at your code?
Your second if has double bracers.. (( condition )) ^~
I think is that linen 115 oO

D.Soul

[code]<?php
# line 115 ????????
//cycle through each sub-array
foreach ( $leadercache as $players )
{
    // verify, else loop
    if ( in_array ( $players['PID'] , $squad ))
    {
        //No one knows for sure what happens past Sergeant Major of the Corps
        //I suspect they become 2nd Lieutenant after Sergeant Major of the Corps, and stay there. (until expansion?)
        if ( $players['RANK'] >= 11 )
        {
          $pcntDiff = number_format ( 100, 2);
          $newrank = "At ease soldier!";[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=368508:date=Apr 25 2006, 11:24 AM:name=Darkness Soul)--][div class=\'quotetop\']QUOTE(Darkness Soul @ Apr 25 2006, 11:24 AM) [snapback]368508[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Is that line 115 before foreach at your code?
Your second if has double bracers.. (( condition )) ^~
I think is that linen 115 oO

D.Soul

[code]<?php
# line 115 ????????
//cycle through each sub-array
foreach ( $leadercache as $players )
{
    // verify, else loop
    if ( in_array ( $players['PID'] , $squad ))
    {
        //No one knows for sure what happens past Sergeant Major of the Corps
        //I suspect they become 2nd Lieutenant after Sergeant Major of the Corps, and stay there. (until expansion?)
        if ( $players['RANK'] >= 11 )
        {
          $pcntDiff = number_format ( 100, 2);
          $newrank = "At ease soldier!";[/code]
[/quote]


I am sorry - I put teh 115 in there. That actually isnt' part of the code i have. I did that. Here is teh whole unedited code for this section.


[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]

<?php
foreach( $leadercache as $players ) { //cycle through each sub-array
if ( in_array($players['PID'], $squad) ) { //verify, else loop

//No one knows for sure what happens past Sergeant Major of the Corps
//I suspect they become 2nd Lieutenant after Sergeant Major of the Corps, and stay there. (until expansion?)
if ( ($players['RANK'] >= 11) ) {
$pcntDiff = number_format( 100, 2);
$newrank = "At ease soldier!";
} else {
//Master Sergeant cannot advance to First Sergeant
//Master Gunnery Sergeant cannot advance to Sergeant Major
if(($players['RANK'] == 7) || ($players['RANK'] == 9))
$nextrank = $players['RANK'] + 2;
else
$nextrank = $players['RANK'] + 1;

$requiredPoints = $rankkeys[$nextrank]['req']; //Required Points for next rank
$pointDiff = ($requiredPoints - $players['SCORE']); //Point differential for next rank

if($pointDiff <= 0) {//WTF? over...
$pcntDiff = number_format( 100, 2);
//gotta find their proper/next rank..
foreach( $rankkeys as $k => $v ) {
if($rankkeys[$k]['req'] >= $players['SCORE']) {
$newrank = $rankkeys[($k - 1)]['rank']; //This is where they're supposed to be
break;
}
}
} else {
$pcntDiff = number_format( (($players['SCORE'] / $requiredPoints) * 100), 2);
$newrank = $rankkeys[$nextrank]['rank'];
$approx = sec2log( floor(($players['TIME'] / $players['SCORE']) * $pointDiff) );
$newrank .= "<br />Aprox.: " . $approx;
}
}
?>

[/quote]

Share this post


Link to post
Share on other sites
That error message indicates that the first argument in the foreach statement is not an array. Is the variable "$leadercache" an array?

Ken

Share this post


Link to post
Share on other sites

×

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.