Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Problem mit foreach

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
eazytrader
Smarty Rookie


Joined: 16 Jul 2010
Posts: 33

PostPosted: Thu Aug 23, 2012 2:55 pm    Post subject: Problem mit foreach Reply with quote

Hallo Leute,

ich habe folgende Schleife und möchte dies per foreach im Template ausgeben lassen.
Das mache ich wie folgt:

Code:
            $query = SQL::Query("SELECT * FROM module_admin_navigation_groups WHERE language_id = '" . SQL::SecureInput($lang->id()) . "' order by navigation_group_sort");
            while($erg = SQL::FetchArray($query)){
                $array[] = $erg;
                $sub_query = SQL::Query("SELECT * FROM module_admin_navigation WHERE navigation_group = '" . $erg['navigation_group_id'] . "' and language_id = '" . SQL::SecureInput($lang->id()) . "' order by navigation_sort");
                while($sub_erg = SQL::FetchArray($sub_query)){
                    $array['subs'][] = $sub_erg;
                }
            }

            return $array;


Und im Template dann:

Code:
{foreach item=var from=$Module->Navigation->Getdata()}
{$var.navigation_group_name}<br />
    {foreach item=sub from=$var.subs}
     -{$sub.navigation_name}<br />
    {/foreach}
{/foreach}


Leider klappt das aber nicht.
Die Ergebnisse des ersten durchlaufs werden korrekt angezeigt.
Die Sub Schleife allerdings nicht. Was mache ich falsch?

Gruss und Danke
Back to top
View user's profile Send private message
TomTo
Smarty Rookie


Joined: 30 May 2009
Posts: 18

PostPosted: Mon Dec 31, 2012 12:15 pm    Post subject: Reply with quote

Gewöhne Dir mal bitte ab Subschleifen in einer anderen zu integrieren, dafür gibt es JOIN Abfragen.
Die Perfomance leidet darunter und für diese Art der DB Abfragen ist das prädestiniert.
Desweiteren wird auch der Fehler dort liegen, weil die erste DB Schleife beendet wurde und daher die zweite keine Daten mehr ins Array liefert.

Frage trotzdem mal vor der Übergabe das Array ab, welche Daten überhaupt vorhanden sind "print_r($array)".
Das sollte man sowieso immer machen, damit man weiss im welchem Bereich der eigentliche Fehler liegt.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP