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

Verschachtelte Schleifen

 
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
Snake
Smarty n00b


Joined: 24 Jun 2004
Posts: 2

PostPosted: Thu Jun 24, 2004 11:36 pm    Post subject: Verschachtelte Schleifen Reply with quote

Hallo Leute,
ich hab nen dickes Problem, bin gerade dabei mich in Smarty einzuarbeiten, hänge nun aber bei verschachtelten Schleifen fest. Also ich ich hab keine Idee wie ich das ausgeben kann. Vllt hat einer ja ne URL oder so nen Codeschnipsel der mir zeigt wie das ganze funktioniert.

Währe für jede Hilfe dankbar

mfg Snake
Back to top
View user's profile Send private message
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Fri Jun 25, 2004 6:03 am    Post subject: Reply with quote

wenn du die struktur deiner variable, die du "durchschleifen" möchtest per "var_dump()" ausgibst und hier postest könnte man dir besser helfen...
Back to top
View user's profile Send private message
Snake
Smarty n00b


Joined: 24 Jun 2004
Posts: 2

PostPosted: Fri Jun 25, 2004 11:24 am    Post subject: Reply with quote

sry versteh net ganz was du meinst aber vllt kann ich mit einem beispiel mein problem klar machen.

Also nehmen wir an ich hab eine Tabelle in der Datenbank (User)
Und eine Tabelle Hobbys.

Jetzt such ich den ersten User mittels while Schleife aus der Tabelle und anhand der ID suche ich in dieser while Schleife mit einer weiteren Schleife nach dieser ID um seine Hobbys rauszubekommen. Die Ausgabe soll dann in etwa so aussehen

User:
Hobby1, Hobby2

User2:

Hobby1, Hobby2

Ich hoffe ich konnte damit mein Problem schildern Sad
Back to top
View user's profile Send private message
till
Smarty Rookie


Joined: 25 Feb 2004
Posts: 19
Location: Berlin, Germany

PostPosted: Thu Jul 08, 2004 12:42 pm    Post subject: sinngemaess Reply with quote

Arrays:

[php:1:fcad372275]<?php
$user[0] = array ("id"=>1, "name"=>"till");
$user[1] = array ("id"=>2, "name"=>"Snake");

$hobbies[1] = array("smarty", "php"); // hobbies von till
$hobbies[2] = array("foo", "bar"); // hobbies von Snake
?>[/php:1:fcad372275]

Code:

{section name=i loop=$user}
   Benutzer: {$user[i].name}<br/>
   {assign name=cUser value=$user[i].id}
   {assign name=cHobbies value=$hobbies[cUser]}
   Hobbies:
    {section name=j loop=$cHobbies}
      {cHobbies[j]}
    {/section}
{/section}


So ungefaehr. Ist vielleicht zu umstaendlich, aber sollte klappen. Smile
Back to top
View user's profile Send private message
coach
Smarty Regular


Joined: 03 Jun 2004
Posts: 65

PostPosted: Thu Jul 08, 2004 1:21 pm    Post subject: Re: sinngemaess Reply with quote

Ein schöneres Array wäre übrigens:

[php:1:cf9ec669e4]<?php
$user[0] = array ("id"=>1, "name"=>"till", 'hobbies'=>array("smarty", "php"));
$user[1] = array ("id"=>2, "name"=>"Snake", 'hobbies'=>array("foo", "bar"));
?>[/php:1:cf9ec669e4]

Bei natürlich anderer Schleife.

Coach
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