mlavwilson Posted May 16, 2007 Share Posted May 16, 2007 On PHP Version 4.4.4 (my development machine) the following code works great. But when I place this on my host which is running 4.3.11, it does not work. Note on line 11, I create an array that is passed into another array on line 22. This seems to be the issue. On 4.4.4 these values passed in on line 22 are remembered. When I run it on 4.3.11, the arguments passed in are forgotten. See bad result. The places where you see "default" should be player names that where set on line 22. This I first thought was a pass by reference/value problem, but that lead me nowhere. Any help would be welcomed, thanks. [pre] 1 $members = array (); 2 $sql = "..."; 3 $result = $xoopsDB->query($sql); 4 while (list ($update, $uid, $uname) = $xoopsDB->fetchRow($result)) 5 { 6 $member = array ("lastUpdate"=>formatTimestamp($update, 'm'), "uid"=>$uid, "uname"=>$uname); 7 $members[] = $member; 8 } 9 $xoopsTpl->assign('members', $members); 10 11 $memberRanks = array(); 12 foreach($members as $member) 13 { 14 $memberRanks[$member["uid"]] = "-"; 15 } 16 17 $averages = array(); 18 $sql = "..."; 19 $result = $xoopsDB->query($sql); 20 while (list ($id, $name, $team, $rank) = $xoopsDB->fetchRow($result)) 21 { 22 $averages[$id] = array("id"=>$id, "name"=>$name, "team"=>$team, "rank"=>$rank, "ranks"=>$memberRanks); 23 } 24 25 26 $sql = "..."; 27 $result = $xoopsDB->query($sql); 28 while (list ($uid, $id, $rank) = $xoopsDB->fetchRow($result)) 29 { 30 $averages[$id]["ranks"][$uid] = $rank; 31 } 32 33 //do averageing and sort... 34 $rankCount = count($averages); 35 $memberCount = count($memberRanks); 36 foreach($averages as $playerId=>$average) 37 { 38 $total = 0; 39 foreach($averages[$playerId]["ranks"] as $uid=>$memberRank) 40 { 41 if ($averages[$playerId]["ranks"][$uid] != "-" ) 42 { 43 $total += $averages[$playerId]["ranks"][$uid]; 44 } 45 else 46 { 47 $total += $rankCount; 48 } 49 } 50 $averages[$playerId]["rank"] = round($total / $memberCount,1); 51 } 52 53 usort(& $averages, "compareValue"); 54 55 $xoopsTpl->assign('averages', $averages); 56 $xoopsOption['template_main'] = 'rank_average.html';[/pre] [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/51726-nested-arrays-in-444-vs-4311/ Share on other sites More sharing options...
mlavwilson Posted May 19, 2007 Author Share Posted May 19, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/51726-nested-arrays-in-444-vs-4311/#findComment-257064 Share on other sites More sharing options...
mlavwilson Posted May 26, 2007 Author Share Posted May 26, 2007 Do I need to give more info here? Or...? Quote Link to comment https://forums.phpfreaks.com/topic/51726-nested-arrays-in-444-vs-4311/#findComment-262042 Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 Clearer problem would help and code in code tags also helps only problem i hear is something about arrays!! whats NOT working ? whats the error etc see my signature for how to ask a question.. also reading the code line by line does help in some ways but most are used to colour formatted text so useing the code tags will help us Quote Link to comment https://forums.phpfreaks.com/topic/51726-nested-arrays-in-444-vs-4311/#findComment-262053 Share on other sites More sharing options...
mlavwilson Posted July 5, 2007 Author Share Posted July 5, 2007 On PHP Version 4.4.4 (my development machine) the following code works great. But when I place this on my host which is running 4.3.11, it does not render the players names that I set in the array on line 22. Note on line 11, I create an array that is passed into another array on line 22. This seems to be the issue. On 4.4.4 these values passed in on line 22 are remembered. When I run it on 4.3.11, the arguments passed in are forgotten. See bad result. The places where you see "default" should be player names that where set on line 22. This I first thought was a pass by reference/value problem, but that lead me nowhere. Any help would be welcomed, thanks. There are no errors logged. 1 $members = array (); 2 $sql = "..."; 3 $result = $xoopsDB->query($sql); 4 while (list ($update, $uid, $uname) = $xoopsDB->fetchRow($result)) 5 { 6 $member = array ("lastUpdate"=>formatTimestamp($update, 'm'), "uid"=>$uid, "uname"=>$uname); 7 $members[] = $member; 8 } 9 $xoopsTpl->assign('members', $members); 10 11 $memberRanks = array(); 12 foreach($members as $member) 13 { 14 $memberRanks[$member["uid"]] = "-"; 15 } 16 17 $averages = array(); 18 $sql = "..."; 19 $result = $xoopsDB->query($sql); 20 while (list ($id, $name, $team, $rank) = $xoopsDB->fetchRow($result)) 21 { 22 $averages[$id] = array("id"=>$id, "name"=>$name, "team"=>$team, "rank"=>$rank, "ranks"=>$memberRanks); 23 } 24 25 26 $sql = "..."; 27 $result = $xoopsDB->query($sql); 28 while (list ($uid, $id, $rank) = $xoopsDB->fetchRow($result)) 29 { 30 $averages[$id]["ranks"][$uid] = $rank; 31 } 32 33 //do averageing and sort... 34 $rankCount = count($averages); 35 $memberCount = count($memberRanks); 36 foreach($averages as $playerId=>$average) 37 { 38 $total = 0; 39 foreach($averages[$playerId]["ranks"] as $uid=>$memberRank) 40 { 41 if ($averages[$playerId]["ranks"][$uid] != "-" ) 42 { 43 $total += $averages[$playerId]["ranks"][$uid]; 44 } 45 else 46 { 47 $total += $rankCount; 48 } 49 } 50 $averages[$playerId]["rank"] = round($total / $memberCount,1); 51 } 52 53 usort(& $averages, "compareValue"); 54 55 $xoopsTpl->assign('averages', $averages); 56 $xoopsOption['template_main'] = 'rank_average.html';[/pre][color=black][/color] Quote Link to comment https://forums.phpfreaks.com/topic/51726-nested-arrays-in-444-vs-4311/#findComment-290629 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.