Jump to content


Photo

Invalid argument supplied for foreach()


  • Please log in to reply
3 replies to this topic

#1 Mobyforce1

Mobyforce1
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 25 April 2006 - 03:48 PM

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

#2 Darkness Soul

Darkness Soul
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts
  • LocationBrazil; São Paulo.

Posted 25 April 2006 - 04:24 PM

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

<?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!";

(If something is wrong, please tell me. I'm learning this language. Thank you)

#3 Mobyforce1

Mobyforce1
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 25 April 2006 - 05:28 PM

[!--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) View Post[/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

<?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!";
[/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]

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 25 April 2006 - 08:52 PM

That error message indicates that the first argument in the foreach statement is not an array. Is the variable "$leadercache" an array?

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users