Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP][JavaScript] Generowanie tablicy
bim2
post 13.09.2008, 15:20:24
Post #1





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 152
Dołączył: 9.04.2006
Skąd: Berlin

Ostrzeżenie: (0%)
-----


Witam, mam pewien problem. W php generuję sobie tablicę

  1. <?php
  2. $sPlayers = 'var Players = new Array(); ';
  3.        foreach($aPlayers AS $value)
  4.        {
  5.            $value['user_name'] = trim($value['user_name']);
  6.            $sPlayers .= 'Players[''.$value['user_name'].''] = new Array(); Players[''.$value['user_name'].'']['name'] = ''.$value['user_name'].''; Players[''.$value['user_name'].'']['x'] = '.$value['posx'].'; Players[''.$value['user_name'].'']['y'] = '.$value['posy'].'; ';
  7.        }
  8.        echo $sPlayers;
  9.        echo 'showPlayersPosition(Players);';
  10. ?>

Pobieram to ajaxem i evaluje co daje mi
Kod
var Players = new Array(); Players['bim'] = new Array(); Players['bim']['name'] = 'bim'; Players['bim']['x'] = 13; Players['bim']['y'] = 15; showPlayersPosition(Players);

Funkcja
Kod
function showPlayersPosition(array)
{
    for(i in array)
    {
        $('#otherPlayers').html(array[i]['name']);
    }
}

Niestety nie wyświetla mi nazwy. Jak dam jednak [i]['x'] to działa ;/ (po uprzednim wywaleniu generowania ['name'] w php.

Wie ktoś może co jest?

EDIT:
Jak dam w showPlayersPosition
alert(array[i]['name']);
to wyświetla Bim -> [pusto] -> [pusto]
Czemu robią się 2 puste tablice?

Ten post edytował bim2 13.09.2008, 15:24:12


--------------------
Go to the top of the page
+Quote Post
lord_t
post 14.09.2008, 22:23:24
Post #2





Grupa: Zarejestrowani
Postów: 603
Pomógł: 131
Dołączył: 24.07.2007
Skąd: Górny Śląsk

Ostrzeżenie: (0%)
-----


Przetestowałem Twój kod na sucho (bez ajaxa) i działa bezproblemowo. alert(array[i]['name']); też.


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 13.07.2025 - 04:45