|
|
|
|
![]() ![]() |
Apr 14 2007, 03:52 PM
Post
#1
|
|
|
Newbie [Level 2] ![]() ![]() Group: Members Posts: 33 Joined: 9-July 06 From: Belgium Member No.: 26,367 |
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: CODE <?php include "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: CODE <?php function getLvlFromHigh($user){ global $highData; $data1 = file_get_contents("<A href="http://hiscore.runescape.com/hiscorepersonal.ws?user1=".$user">http://hiscore.runescape.com/hiscorepersonal.ws?user1=".$user); $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 This post has been edited by peroim: Apr 14 2007, 03:54 PM |
|
|
|
Apr 14 2007, 06:04 PM
Post
#2
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 397 Joined: 9-June 06 From: Wisconsin Member No.: 24,924 |
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. |
|
|
|
Apr 16 2007, 05:05 PM
Post
#3
|
|
|
Newbie [Level 2] ![]() ![]() Group: Members Posts: 33 Joined: 9-July 06 From: Belgium Member No.: 26,367 |
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 |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 8th September 2008 - 06:13 PM |