Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> smarty i foreach
kajtek2008
post 10.11.2012, 10:16:51
Post #1





Grupa: Zarejestrowani
Postów: 69
Pomógł: 0
Dołączył: 15.08.2009
Skąd: Nowy Sącz

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


Kod
Array
(
    [0] => Array
        (
            [id] => 1
            [tytul] => Biznes
            [status] => 2
            [meta_desc] =>
            [sub] => Array
                (
                    [0] => Array
                        (
                            [id] => 6
                            [id_kat] => 1
                            [tytul] => Praca
                            [status] => 2
                            [meta_desc] =>
                        )

                )

        )

    [1] => Array
        (
            [id] => 2
            [tytul] => Ekonomia
            [status] => 2
            [meta_desc] =>
        )

    [2] => Array
        (
            [id] => 3
            [tytul] => Internet i komputery
            [status] => 2
            [meta_desc] =>
            [sub] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [id_kat] => 3
                            [tytul] => Programy
                            [status] => 2
                            [meta_desc] =>
                        )

                    [1] => Array
                        (
                            [id] => 2
                            [id_kat] => 3
                            [tytul] => Grafika
                            [status] => 2
                            [meta_desc] =>
                        )

                )

        )

)





Mam problem z wyciągnięciem drzewka


Biznes:
-Praca
Ekonomia:
Internet i komputery:
-Programy
-Grafika


Próbowałem przez foreach w foreach ale dalej wyskakuje ze jest tablica

sub:array
Go to the top of the page
+Quote Post
d3ut3r
post 10.11.2012, 10:47:10
Post #2





Grupa: Zarejestrowani
Postów: 709
Pomógł: 176
Dołączył: 24.10.2010

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


  1. {foreach from=$zmienna item=element}
  2.  
  3. {$element.tytul}
  4.  
  5. {if $element.sub|@count gt 0}
  6. {foreach from=$element.sub item=subelement}
  7. - {$subelement.tytul}
  8. {/foreach}
  9. {/if}
  10.  
  11. {/foreach}


o to chodzi?


--------------------
http://d3ut3r.wordpress.com/ | mysql_* jest przestarzałe UŻYWAJ PDO!
Go to the top of the page
+Quote Post
kajtek2008
post 10.11.2012, 10:53:58
Post #3





Grupa: Zarejestrowani
Postów: 69
Pomógł: 0
Dołączył: 15.08.2009
Skąd: Nowy Sącz

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


Omg jaki miałem durny bład
Faktycznie zamiast $element.sub miałem wpisane $element[sub]

Dzięki wielkie 2h nad tym spędziłem smile.gif

Ten post edytował kajtek2008 10.11.2012, 10:54:32
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: 28.04.2024 - 15:31