Jump to content

copy an array?


GRooVeZ

Recommended Posts

hi i made my very first array, and its working great :)

 

now i want to have another array wich does the same thing, but on another category,

it shows gold silver and bronze logos, but now i want to give leaders of other categorys also those logos, but different ones

 

so i thought

i change from

 

$array[$snipergameid][$x] = $sniperleaders[playerid]; (part of the code in a while loop)

 

into

 

$array2[$snipergameid][$x] = $sniperleaders[playerid]; (part of the code in a while loop)

 

and i do the same for the result checker loops

but that doesnt work

 

so how do i copy an entire arrray, and give it another name

to match it with the correct while loop checker?

 

 

Link to comment
https://forums.phpfreaks.com/topic/261139-copy-an-array/
Share on other sites

$sniperchecker = mysql_query ("SELECT id FROM `ffa_games`");

 

while($snipergames = mysql_fetch_array($sniperchecker))

{

$snipergameid = $snipergames[id];

$x = 1;

 

$sniperchecker2 = mysql_query ("SELECT playerid FROM ffa_rankings where gameid=$snipergameid and typeid=2 order by points desc");

while($sniperleaders = mysql_fetch_array($sniperchecker2))

{

$array[$snipergameid][$x] = $sniperleaders[playerid];

$x++;

}

 

}

 

 

 

$snipergameschecker2 = mysql_query ("SELECT id FROM `ffa_games`");

while($snipergames2 = mysql_fetch_array($snipergameschecker2))

{

$snipergameid2 = $snipergames2[id];

if ($mem[id] == $array[$snipergameid2][1])

{

$out[body].=" <img src='./images/icons/sniper1.png' title='Leader in a Sniper Ranking'>";

}

if ($mem[id] == $array[$snipergameid2][2])

{

$out[body].=" <img src='./images/icons/sniper2.png' title='2nd in a Sniper Ranking'>";

}

if ($mem[id] == $array[$snipergameid2][3])

{

$out[body].=" <img src='./images/icons/sniper3.png' title='3th in a Sniper Ranking'>";

}

 

}

 

this is the array i made, wich is working

 

now i want another one, and i did this

 

$sniperchecker = mysql_query ("SELECT id FROM `ffa_games`");

 

while($snipergames = mysql_fetch_array($sniperchecker))

{

$snipergameid = $snipergames[id];

$x = 1;

 

$sniperchecker2 = mysql_query ("SELECT playerid FROM ffa_rankings where gameid=$snipergameid and typeid=2 order by points desc");

while($sniperleaders = mysql_fetch_array($sniperchecker2))

{

$array[$snipergameid][$x] = $sniperleaders[playerid];

$x++;

}

 

 

$allgunschecker2 = mysql_query ("SELECT playerid FROM ffa_rankings where gameid=$snipergameid and typeid=1 order by points desc");

while($allgunsleaders = mysql_fetch_array($allgunschecker2))

{

$array2[$snipergameid][$x] = $allgunsleaders[playerid];

$x++;

}

 

 

}

 

$snipergameschecker2 = mysql_query ("SELECT id FROM `ffa_games`");

while($snipergames2 = mysql_fetch_array($snipergameschecker2))

{

$snipergameid2 = $snipergames2[id];

if ($mem[id] == $array[$snipergameid2][1])

{

$out[body].=" <img src='./images/icons/sniper1.png' title='Leader in a Sniper Ranking'>";

}

if ($mem[id] == $array[$snipergameid2][2])

{

$out[body].=" <img src='./images/icons/sniper2.png' title='2nd in a Sniper Ranking'>";

}

if ($mem[id] == $array[$snipergameid2][3])

{

$out[body].=" <img src='./images/icons/sniper3.png' title='3th in a Sniper Ranking'>";

}

if ($mem[id] == $array2[$snipergameid2][1])

{

$out[body].=" <img src='./images/icons/ak1.png' title='Leader in a Sniper Ranking'>";

}

if ($mem[id] == $array2[$snipergameid2][2])

{

$out[body].=" <img src='./images/icons/ak2.png' title='2nd in a Sniper Ranking'>";

}

if ($mem[id] == $array2[$snipergameid2][3])

{

$out[body].=" <img src='./images/icons/ak.png' title='3th in a Sniper Ranking'>";

}

}

Link to comment
https://forums.phpfreaks.com/topic/261139-copy-an-array/#findComment-1338274
Share on other sites

I can't even decipher the logic behind your code, it's a mess.

 

1. you should be joining queries together instead of querying inside of a while loop, this will save resources and cut down on server load times.

 

Please explain in English exactly what you are trying to do so we can assist you further.

Link to comment
https://forums.phpfreaks.com/topic/261139-copy-an-array/#findComment-1338380
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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