![]() ![]() |
Post
#1
|
|
|
Grupa: Zarejestrowani Postów: 62 Pomógł: 0 Dołączył: 22.05.2009 Ostrzeżenie: (0%)
|
Mam listę kategorii pobraną w ten sposób:
Jak się dostać to poszczególnych elementów tablicy po indeksie? Dla testów wypisuje sobie nazwy kategorii w pętli foreach, z tym nie ma żadnych problemów, wypisuje się jak trzeba.
Problem pojawia się jak próbuję dostać się do tej tablicy po indeksie Wypisuje się tylko kategoria z indeksem 0. Te z indeksem 1 i 2 się nie wypisują. Jak się dostać do tych elementów? get_categories() zwraca tablicę obiektów. Ten post edytował Vill 5.09.2014, 11:55:59 |
|
|
|
Post
#2
|
|
|
Grupa: Zarejestrowani Postów: 1 270 Pomógł: 184 Dołączył: 7.10.2012 Skąd: Warszawa Ostrzeżenie: (0%)
|
|
|
|
|
Post
#3
|
|
|
Grupa: Nieautoryzowani Postów: 2 249 Pomógł: 305 Dołączył: 2.10.2006 Ostrzeżenie: (0%)
|
|
|
|
|
Post
#4
|
|
|
Grupa: Zarejestrowani Postów: 62 Pomógł: 0 Dołączył: 22.05.2009 Ostrzeżenie: (0%)
|
|
|
|
|
Post
#5
|
|
|
Grupa: Zarejestrowani Postów: 1 270 Pomógł: 184 Dołączył: 7.10.2012 Skąd: Warszawa Ostrzeżenie: (0%)
|
To pokaz output z var dumpa
|
|
|
|
Post
#6
|
|
|
Grupa: Zarejestrowani Postów: 62 Pomógł: 0 Dołączył: 22.05.2009 Ostrzeżenie: (0%)
|
Cytat array (size=3)
0 => object(stdClass)[1759] public 'term_id' => &string '1' (length=1) public 'name' => &string 'Bez kategorii' (length=13) public 'slug' => &string 'bez-kategorii' (length=13) public 'term_group' => string '0' (length=1) public 'term_taxonomy_id' => string '1' (length=1) public 'taxonomy' => string 'category' (length=8) public 'description' => &string '' (length=0) public 'parent' => &string '0' (length=1) public 'count' => &string '1' (length=1) public 'cat_ID' => &string '1' (length=1) public 'category_count' => &string '1' (length=1) public 'category_description' => &string '' (length=0) public 'cat_name' => &string 'Bez kategorii' (length=13) public 'category_nicename' => &string 'bez-kategorii' (length=13) public 'category_parent' => &string '0' (length=1) 2 => object(stdClass)[1761] public 'term_id' => &string '2' (length=1) public 'name' => &string 'Kategoria 1' (length=11) public 'slug' => &string 'kategoria1' (length=10) public 'term_group' => string '0' (length=1) public 'term_taxonomy_id' => string '2' (length=1) public 'taxonomy' => string 'category' (length=8) public 'description' => &string '' (length=0) public 'parent' => &string '0' (length=1) public 'count' => &string '1' (length=1) public 'cat_ID' => &string '2' (length=1) public 'category_count' => &string '1' (length=1) public 'category_description' => &string '' (length=0) public 'cat_name' => &string 'Kategoria 1' (length=11) public 'category_nicename' => &string 'kategoria1' (length=10) public 'category_parent' => &string '0' (length=1) 3 => object(stdClass)[1762] public 'term_id' => &string '4' (length=1) public 'name' => &string 'Kategoria 2' (length=11) public 'slug' => &string 'kategoria2' (length=10) public 'term_group' => string '0' (length=1) public 'term_taxonomy_id' => string '4' (length=1) public 'taxonomy' => string 'category' (length=8) public 'description' => &string '' (length=0) public 'parent' => &string '0' (length=1) public 'count' => &string '2' (length=1) public 'cat_ID' => &string '4' (length=1) public 'category_count' => &string '2' (length=1) public 'category_description' => &string '' (length=0) public 'cat_name' => &string 'Kategoria 2' (length=11) public 'category_nicename' => &string 'kategoria2' (length=10) public 'category_parent' => &string '0' (length=1) |
|
|
|
Post
#7
|
|
|
Grupa: Nieautoryzowani Postów: 2 249 Pomógł: 305 Dołączył: 2.10.2006 Ostrzeżenie: (0%)
|
|
|
|
|
Post
#8
|
|
|
Grupa: Zarejestrowani Postów: 62 Pomógł: 0 Dołączył: 22.05.2009 Ostrzeżenie: (0%)
|
Cytat string 'Bez kategorii' (length=13)
string 'Kategoria 1' (length=11) string 'Kategoria 2' (length=11) |
|
|
|
Post
#9
|
|
|
Grupa: Nieautoryzowani Postów: 2 249 Pomógł: 305 Dołączył: 2.10.2006 Ostrzeżenie: (0%)
|
Czyli pętla śmiga. A nie masz Ty czasem jakiegoś problemu ze stylem, który powoduje, że przy echo masz tekst ukryty? CSS? Albo niedomknięty tag?
|
|
|
|
Post
#10
|
|
|
Grupa: Zarejestrowani Postów: 62 Pomógł: 0 Dołączył: 22.05.2009 Ostrzeżenie: (0%)
|
Nie, zwykły tekst się wypisuje bez problemu.
$categories[0]->name też, jedynie indeksy od 1 w górę mają problem z wypisywaniem się |
|
|
|
Post
#11
|
|
|
Grupa: Zarejestrowani Postów: 1 270 Pomógł: 184 Dołączył: 7.10.2012 Skąd: Warszawa Ostrzeżenie: (0%)
|
A dlaczego masz przeskok w indekach 0,2,3 moze to jest przyczyna. Skprobuj wypisac bez indeksu 1
Ten post edytował rad11 5.09.2014, 12:08:57 |
|
|
|
Post
#12
|
|
|
Grupa: Zarejestrowani Postów: 62 Pomógł: 0 Dołączył: 22.05.2009 Ostrzeżenie: (0%)
|
Faktycznie, ma pusty obiekt w tablicy. Foreach zwraca same istniejące, a idąc po indeksach natrafia się na puste obiekty, wtedy nic nie wypisuje. Hmm, myślałam że ta funkcja mi załatwi filtrowanie, ale widocznie nie załatwiła (IMG:style_emoticons/default/smile.gif) No to dopiszę sobie sprawdzanie czy obiekt nie jest pusty i problem rozwiązany (IMG:style_emoticons/default/smile.gif) .
Ten post edytował Vill 5.09.2014, 12:18:05 |
|
|
|
![]() ![]() |
|
Aktualny czas: 23.12.2025 - 00:07 |