Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][JavaScript] Generowanie tablicy
bim2
post
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

Posty w temacie


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

 



RSS Aktualny czas: 18.09.2025 - 01:14