i'm not sure if you made a mistake in your fontifying this line or not,
echo "$Player_Num :[/color {$Player[$Player_Num]['Name']}<br>";
but i figure you dont know about the <php></php> tag they have here. use that instead. it's much easier and you can copy and paste your code. only swith < to [ and > to ].
here' swhat that (assumeing there's no mistakes) llooks like with the tags:Code: Select all
$Player[1]['Name'] = "Joe";
$Player[1]['Rank'] = "Newbie";
$Player[1]['Skills']['Digging'] = 0;
for ($Player_Num = 1; $Player_Num <= 10; $Player++)
{
echo "$Player_Num :[/color {[color=blue]$Player[$Player_Num]['Name']}<br>";
echo $Player[$Player_Num]['Rank'] . '<br>';
foreach ($Player[$Player_Num]['Skills'] as $Skills)
foreach ($Skills as $Skill)
echo "$Skills : $Skill<br>";
}
the error you're getting is because you are giving the wrong thing to foreach. you also can't use arrays directly in quoted strings like that. i know there's a way but can't think of it. i assume this is a top ten, so...
Code: Select all
$ranklist='<ol>'; // make a string you can echo out later that has all the top ten
$findpeople=mysql_query(/*select statement*/); // find the top ten
$ppl=mysql_num_rows($findpeople); /// how many did we get?
if($ppl<11){ // less than 11 ppl // there's no more than 10
for($i=0;$i<ppl;$i++){ // for each person
$getperson=mysql_fetch_array($findpeople); // get the person
$person=$getperson['name']; $playernum=$getperson['num']; // get the person's info
$rank=$getperson['rank']; $skills=$getperson['skills']; // get the person's info
$ranklist.="<li>Player: $person<br />Rank: $rank<br />skills: skill->sill level<ul>"; // set the easy into into the ranklist
foreach($skills as $skill=>$skilllevel){ // for each skill (key) and skilllevel (value)
$ranklist.="<li>$skill -> $skilllevel</li>"; // add the skill and value to the rank list
}
}
}else{ // there's more than ten
for($i=0;$i<10;$i++){ // for each person
$getperson=mysql_fetch_array($findpeople); // get the person
$person=$getperson['name']; $playernum=$getperson['num']; // get the person's info
$rank=$getperson['rank']; $skills=$getperson['skills']; // get the person's info
$ranklist.="<li>Player: $person<br />Rank: $rank<br />skills: skill->sill level<ul>"; // set the easy into into the ranklist
foreach($skills as $skill=>$skilllevel){ // for each skill (key) and skilllevel (value)
$ranklist.="<li>$skill -> $skilllevel</li>"; // add the skill and value to the rank list
}
}
}
you should try the search feature at php.net. it have better write up on functions than books, as well as more current ones since it's php's home.
for more info on foreach loops, search
php.net
you did good there, there's just a number of small things including the foreach issue that you should check php.net on. generally type issues and how to get around them are there.
for the most part that's all i've fixed. if you need me to explain something, just let me know