1josh13 Posted April 18, 2009 Share Posted April 18, 2009 Hey again guys, I get the following error "Warning: Invalid argument supplied for foreach() in /home/evewebsp/public_html/v2/api/index.php on line 145" The code is: (from lines 143 to 167) <?php if(!count($keys) < 1){ foreach($userChars as $key => $value){ switch($value["info"]["skilllevel"]){ case 0: $value["info"]["skilllevel"] = $value["info"]["skilllevel"]; break; case 1: $value["info"]["skilllevel"] = "I"; break; case 2: $value["info"]["skilllevel"] = "II"; break; case 3: $value["info"]["skilllevel"] = "III"; break; case 4: $value["info"]["skilllevel"] = "IV"; break; case 5: $value["info"]["skilllevel"] = "V"; break; default: $value["info"]["skilllevel"] = "unknown"; } Quote Link to comment https://forums.phpfreaks.com/topic/154603-invalid-arguement-help/ Share on other sites More sharing options...
Daniel0 Posted April 18, 2009 Share Posted April 18, 2009 It's because $userChars isn't an array, which makes it an invalid argument for foreach that expects an array. Quote Link to comment https://forums.phpfreaks.com/topic/154603-invalid-arguement-help/#findComment-812994 Share on other sites More sharing options...
1josh13 Posted April 18, 2009 Author Share Posted April 18, 2009 so hw would I edit it to make it an array? or just to work? Quote Link to comment https://forums.phpfreaks.com/topic/154603-invalid-arguement-help/#findComment-813231 Share on other sites More sharing options...
Daniel0 Posted April 18, 2009 Share Posted April 18, 2009 Just check if it's an array and don't run the loop if it isn't. Quote Link to comment https://forums.phpfreaks.com/topic/154603-invalid-arguement-help/#findComment-813240 Share on other sites More sharing options...
1josh13 Posted April 18, 2009 Author Share Posted April 18, 2009 So the code to find if its array would be:?? <?php $yes = array('$userChars'); echo is_array($yes) ? 'Array' : 'not an Array'; echo "\n"; $no = 'this is a string'; echo is_array($no) ? 'Array' : 'not an Array'; ?> Correct? If so then I get "not an array", where do I go from here? Quote Link to comment https://forums.phpfreaks.com/topic/154603-invalid-arguement-help/#findComment-813262 Share on other sites More sharing options...
Daniel0 Posted April 18, 2009 Share Posted April 18, 2009 Well, more like: if (is_array($userChars)) { // foreach loop here } Quote Link to comment https://forums.phpfreaks.com/topic/154603-invalid-arguement-help/#findComment-813264 Share on other sites More sharing options...
wildteen88 Posted April 18, 2009 Share Posted April 18, 2009 Where and how is the $userChars variable being set? Quote Link to comment https://forums.phpfreaks.com/topic/154603-invalid-arguement-help/#findComment-813266 Share on other sites More sharing options...
1josh13 Posted April 18, 2009 Author Share Posted April 18, 2009 Where and how is the $userChars variable being set? TBH, a friend gave me this code, so I wouldnt know where exactly to look, And with the arrays, i dont think i got it working EDIT: I believe that i have found where the $userChars variable is being set: <?php $userChars = array(); $sql = "SELECT * FROM `api_chardetails` WHERE `characterID` = '".$characterID."'"; $userdata = $dbc->Query($sql); $userChars[$characterID]["details"] = mysql_fetch_assoc($userdata); $sql = "SELECT * FROM `api_chars` WHERE `characterID` = '".$characterID."'"; $userDetails = $dbc->Query($sql); $userChars[$characterID]["info"] = mysql_fetch_assoc($userDetails); $sql = "SELECT * FROM `api_charsheet` WHERE `characterID` = '".$characterID."'"; $userskills = $dbc->Query($sql); while($userSkillTemp = mysql_fetch_assoc($userskills)){ $index = count($userSkill); $userSkill[$index] = $userSkillTemp; } $userChars[$characterID]["skills"] = $userSkill; $toon["intelligence"] = $userChars[$characterID]["details"]['intelligence']; $toon["memory"] = $userChars[$characterID]["details"]['memory']; $toon["charisma"] = $userChars[$characterID]["details"]['charisma']; $toon["perception"] = $userChars[$characterID]["details"]['perception']; $toon["willpower"] = $userChars[$characterID]["details"]['willpower']; foreach($userChars[$characterID]["skills"] as $key => $value){ $index = count($skills); $skills[$index]["skillgroup"] = $api->GetGroupID($value['typeID'], $dataBase); $skills[$index]["skillname"] = $api->GetTypeName($value['typeID'], $dataBase); $skills[$index]["skillpoints"] = $value['skillpoints']; $skills[$index]["skilllevel"] = $value['level']; $skillpoints = $skillpoints + $value['skillpoints']; } sort($skills); foreach($skills as $key => $value){ if($value["skillgroup"] == 267){ if($value["skillname"] === "Logic" || $value["skillname"] === "Analytical Mind"){ $toon["intelligence"] = $toon["intelligence"] + $value['skilllevel']; } if($value["skillname"] === "Spatial Awareness" || $value["skillname"] === "Clarity"){ $toon["perception"] = $toon["perception"] + $value['skilllevel']; } if($value["skillname"] === "Instant Recall" || $value["skillname"] === "Eidetic Memory"){ $toon["memory"] = $toon["memory"] + $value['skilllevel']; } if($value["skillname"] === "Presence" || $value["skillname"] === "Empathy"){ $toon["charisma"] = $toon["charisma"] + $value['skilllevel']; } if($value["skillname"] === "Iron Will" || $value["skillname"] === "Focus"){ $toon["willpower"] = $toon["willpower"] + $value['skilllevel']; } if($value["skillname"] === "Learning"){ $sl = $value['skilllevel']; for($y = 0; $y < ($sl +1); $y ++){ $intelligence = ($toon["intelligence"] * 0.02); $toon["intelligence"] = $toon["intelligence"] + $intelligence; $perception = ($toon["perception"] * 0.02); $toon["perception"] = $toon["perception"] + $perception; $memory = ($toon["memory"] * 0.02); $toon["memory"] = $toon["memory"] + $memory; $charisma = ($toon["charisma"] * 0.02); $toon["charisma"] = $toon["charisma"] + $charisma; $willpower = ($toon["willpower"] * 0.02); $toon["willpower"] = $toon["willpower"] + $willpower; } } } } $toon["intelligence"] = $toon["intelligence"] + $userChars[$characterID]["details"]["attribute1"]; $toon["perception"] = $toon["perception"] + $userChars[$characterID]["details"]["attribute5"]; $toon["memory"] = $toon["memory"] + $userChars[$characterID]["details"]["attribute2"]; $toon["charisma"] = $toon["charisma"] + $userChars[$characterID]["details"]["attribute3"]; $toon["willpower"] = $toon["willpower"] + $userChars[$characterID]["details"]["attribute4"]; if($userChars[$characterID]["details"]["attribute1"] > 0){ $chardeatils["enhancers"][1]['augmentatorName'] = $userChars[$characterID]["details"]["attributename1"]; $chardeatils["enhancers"][1]['augmentatorValue'] = $userChars[$characterID]["details"]["attribute1"]; } if($userChars[$characterID]["details"]["attribute2"] > 0){ $chardeatils["enhancers"][2]['augmentatorName'] = $userChars[$characterID]["details"]["attributename2"]; $chardeatils["enhancers"][2]['augmentatorValue'] = $userChars[$characterID]["details"]["attribute2"]; } if($userChars[$characterID]["details"]["attribute3"] > 0){ $chardeatils["enhancers"][3]['augmentatorName'] = $userChars[$characterID]["details"]["attributename3"]; $chardeatils["enhancers"][3]['augmentatorValue'] = $userChars[$characterID]["details"]["attribute3"]; } if($userChars[$characterID]["details"]["attribute4"] > 0){ $chardeatils["enhancers"][4]['augmentatorName'] = $userChars[$characterID]["details"]["attributename4"]; $chardeatils["enhancers"][4]['augmentatorValue'] = $userChars[$characterID]["details"]["attribute4"]; } if($userChars[$characterID]["details"]["attribute5"] > 0){ $chardeatils["enhancers"][5]['augmentatorName'] = $userChars[$characterID]["details"]["attributename5"]; $chardeatils["enhancers"][5]['augmentatorValue'] = $userChars[$characterID]["details"]["attribute5"]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/154603-invalid-arguement-help/#findComment-813271 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.