Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]index tablicy
hmtt
post
Post #1





Grupa: Zarejestrowani
Postów: 27
Pomógł: 0
Dołączył: 7.06.2008

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


Witam!

Mam taki oto fragment kodu.

  1. <?php
  2. $index = simplexml_load_file('index.xml');
  3. foreach($index->produkty[0] as $i) {
  4. $test = $i->attributes()->nazwa;
  5. echo $test;
  6. $this->produkty[$test] = $i->attributes()->link;
  7. }
  8. ?>


Problem polega na tym że skrypt pokazuje błąd kiedy jako index do tabeli podaję nazwę produktu wczytaną z pliku XML.

Pozdrawiam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
mike
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

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


Przed pętlę daj: $this->produkty = array();
Go to the top of the page
+Quote Post
hmtt
post
Post #3





Grupa: Zarejestrowani
Postów: 27
Pomógł: 0
Dołączył: 7.06.2008

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


Nadal coś nie działa - ten sam błąd.

  1. <?php
  2. class Product {
  3. public $produkty;
  4.  
  5. public function __construct() {
  6. $index = simplexml_load_file('index.xml');
  7. $this->produkty = array();
  8. foreach($index->produkty[0] as $i) {
  9. $test = $i->attributes()->nazwa;
  10. echo $test;
  11. $this->produkty[$test] = $i->attributes()->link;
  12. }
  13. }
  14.  
  15. }
  16. ?>
Go to the top of the page
+Quote Post

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: 23.08.2025 - 07:01