Jump to content

nested arrays in 4.4.4 vs. 4.3.11


mlavwilson

Recommended Posts

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 month later...

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.