Mobyforce1 Posted April 25, 2006 Share Posted April 25, 2006 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--]<?phpline 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 Quote Link to comment https://forums.phpfreaks.com/topic/8376-invalid-argument-supplied-for-foreach/ Share on other sites More sharing options...
Darkness Soul Posted April 25, 2006 Share Posted April 25, 2006 Is that line 115 before foreach at your code?Your second if has double bracers.. (( condition )) ^~I think is that linen 115 oOD.Soul[code]<?php# line 115 ????????//cycle through each sub-arrayforeach ( $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 Link to comment https://forums.phpfreaks.com/topic/8376-invalid-argument-supplied-for-foreach/#findComment-30617 Share on other sites More sharing options...
Mobyforce1 Posted April 25, 2006 Author Share Posted April 25, 2006 [!--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 oOD.Soul[code]<?php# line 115 ????????//cycle through each sub-arrayforeach ( $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] Quote Link to comment https://forums.phpfreaks.com/topic/8376-invalid-argument-supplied-for-foreach/#findComment-30645 Share on other sites More sharing options...
kenrbnsn Posted April 25, 2006 Share Posted April 25, 2006 That error message indicates that the first argument in the foreach statement is not an array. Is the variable "$leadercache" an array?Ken Quote Link to comment https://forums.phpfreaks.com/topic/8376-invalid-argument-supplied-for-foreach/#findComment-30726 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.