Jump to content
xisto Community
Sign in to follow this  
peroim

Problem With Global Arrays

Recommended Posts

I've got a problem with global variables. ;) I've read and re-read the stuff about that on php.net and did that a few times more, and I'm still not able to make it work.Could somebody please fix my code?This is the primary page:

<?phpinclude "getLvlFromHigh.func";$user = $_GET["user"];$skill = $_GET["skill"];$goal = $_GET["goal"];$userXp = getLvlFromHigh($user);$xpTable = array( 31 => 14833, 32 => 16456, 33 => 18247, 34 => 20224, 35 => 22406, 36 => 24815, 37 => 27473, 38 => 30408, 39 => 33648, 40 => 37224, 41 => 41171, 42 => 45529, 43 => 50339, 44 => 55649, 45 => 61512, 46 => 67983, 47 => 75127, 48 => 83014, 49 => 91721, 50 => 101333, 51 => 111945, 52 => 123660, 53 => 136594, 54 => 150872, 55 => 166636, 56 => 184040, 57 => 203254, 58 => 224466, 59 => 247886, 60 => 273742, 61 => 302288, 62 => 333804, 63 => 368599, 64 => 407015, 65 => 449428, 66 => 496254, 67 => 547953, 68 => 605032, 69 => 668051, 70 => 737627, 71 => 814445, 72 => 899257, 73 => 992895, 74 => 1096278, 75 => 1210421, 76 => 1336443, 77 => 1475581, 78 => 1629200, 79 => 1798808, 80 => 1986068, 81 => 2192818, 82 => 2421087, 83 => 2673114, 84 => 2951373, 85 => 3258594, 86 => 3597792, 87 => 3972294, 88 => 4385776, 89 => 4842295, 90 => 5346332, 91 => 5902831, 92 => 6517253, 93 => 7195629, 94 => 7944614, 95 => 8771558, 96 => 9684577, 97 => 10692629, 98 => 11805606, 99 => 13034431);if($goal > 99) $goal = 99;$procent = floor($userXp / $xpTable[$goal] * 100);if($procent >= 100){ echo "You have accomplished your goal.";}else{// echo "You have ".$procent."% of your goal.";}?>

And this is getLvlFromHigh.func:

<?phpfunction getLvlFromHigh($user){ global $highData; $data1 = file_get_contents("<A href="http://forums.xisto.com/no_longer_exists/); $data2 = explode("<td width=\"380\">\n<table>", $data1); $data3 = explode("</table>\n</div>\n</div>\n</div>", $data2[1]); $data3 = $data3[0]; $data3 = explode("\n", $data3); $data4 = ""; foreach($data3 as $i => $contains){  if(($i > 13) && ($i < 212))  $data4 = $data4."\n".$contains; } $data4 = explode("</tr>\n<tr>", $data4); foreach($data4 as $skill => $contains){  if(stristr($contains, "Not ranked")){   $data[$skill] = false;  }  else {   $data5 = explode("\n", $contains);   $data5 = preg_replace("|<td align=\"right\">(.*?)</td>|","$1",$data5);   $data5 = str_replace(",","",$data5);   $highData = array();   $highData[$skill]["rank"] = $data5[5];   $highData[$skill]["lvl"] = $data5[6];   $highData[$skill]["xp"] = $data5[7];  } }}echo "Overall rank: ".$highData[0]["rank"]."; lvl: ".$highData[0]["lvl"]."; xp: ".$highData[0]["xp"].";<br />";?>

I know goal.php won't work yet, but I'm currently working on getting the data with getLvlFromHigh.func...The output of this script is:Overall rank: ; lvl: ; xp: ;While it should give some data from the RuneScape-highscores.Please help me with this...Peroim

Edited by peroim (see edit history)

Share this post


Link to post
Share on other sites

You have double quotes (") inside of your brackets for your array. Change all of these to single quotes (') and you should be fine.Also as a side note, when you are declaring numerical arrays (arrays that have keys that are integers), you only need to define the first key. After that you can omit the key and simply put the value in.Post back here if it doesn't work. Be sure to include error messages.

Share this post


Link to post
Share on other sites

Thanks Ghostrider, the double quotes were wrong as you said.After changing that, and some testing it still didn't work... ;) But after some more testing, I finally found out what was wrong too: better avoid arrays in arrays...And thanks for the numeric array-tip, that's indeed a lot easyer! ;) Peroim

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.