Jump to content

Invalid arguement, help


1josh13

Recommended Posts

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";								
		}

 

 

Link to comment
https://forums.phpfreaks.com/topic/154603-invalid-arguement-help/
Share on other sites

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?

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 :P

 

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"];
}


?>

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.