Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Sax Parser php nieparzyste id
OpsS
post
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 29.01.2017

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


Staram się uzyskać dane z xml o nieparzystej wartości id. Kiedy ustawię żeby id było nieparzyste to owszem jest, ale się dubluje wartości oraz są one z parzystych id. Jak mogę to poprawić?


Poniższy obrazek przedstawia jak wygląda tabela
Zdjęcia

  1. class ksiazka extends SAXParser {
  2.  
  3. public $book_tab = array();
  4. public $books;
  5.  
  6. public function startElement($parser, $name, $attributes) {
  7. $this->tagName = $name;
  8. if ($name == "book" && $attributes['id'] % 2 == 1) {
  9. $this->books = new Books();
  10. $this->books->ID = $attributes['id'];
  11. }
  12. }
  13.  
  14.  
  15. public function characterData($parser, $data) {
  16. if ($this->tagName == "title") {
  17. $this->books->TITLE = $data;
  18. }
  19. }
  20.  
  21. public function endElement($parser, $name) {
  22. $this->tagName = "";
  23. if ($name == "book") {
  24. $this->book_tab[] = $this->books;
  25. }
  26.  
  27. }
  28. }
  29.  
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
OpsS
post
Post #2





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 29.01.2017

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


Jak tak daje to mam takie błędy


Notice: Array to string conversion in C:\xampp\htdocs\parser\books.php on line 61

Notice: Undefined property: ksiazka::$Array in C:\xampp\htdocs\parser\books.php on line 61

Warning: Creating default object from empty value in C:\xampp\htdocs\parser\books.php on line 69


  1. public function startElement($parser, $name, $attributes) {
  2. $this->tagName = $name;
  3. if ($name == "book" && $attributes['id'] % 2 == 1) {
  4. $this->books = new Books();
  5. $this->books->ID = $this -> $attributes['id'];
  6.  
  7. } else
  8. { $this->books = null;}
  9. }
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: 13.10.2025 - 10:31