|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Maxcube Smarty n00b
Joined: 28 Jul 2004 Posts: 3
|
Posted: Wed Jul 28, 2004 9:54 pm Post subject: Loop in Loop wie ? |
|
|
Hi,
ich bin neu bei Smarty und kenne mich damit noch nicht so recht aus.
Kann mir bitte einer erklären wie ich einen Loop in einen Loop mache ?
mfg.
Maxcube |
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Thu Jul 29, 2004 7:14 am Post subject: |
|
|
schau hier ma rein:
http://smarty.php.net/manual/en/language.function.section.php
Quote: |
Example 7-18. nested sections
{* sections can be nested as deep as you like. With nested sections,
you can access complex data structures, such as multi-dimensional
arrays. In this example, $contact_type[customer] is an array of
contact types for the current customer. *}
{section name=customer loop=$custid}
id: {$custid[customer]}<br>
name: {$name[customer]}<br>
address: {$address[customer]}<br>
{section name=contact loop=$contact_type[customer]}
{$contact_type[customer][contact]}: {$contact_info[customer][contact]}<br>
{/section}
<p>
{/section}
OUTPUT:
id: 1000<br>
name: John Smith<br>
address: 253 N 45th<br>
home phone: 555-555-5555<br>
cell phone: 555-555-5555<br>
e-mail: john@mydomain.com<br>
<p>
id: 1001<br>
name: Jack Jones<br>
address: 417 Mulberry ln<br>
home phone: 555-555-5555<br>
cell phone: 555-555-5555<br>
e-mail: jack@mydomain.com<br>
<p>
id: 1002<br>
name: Jane Munson<br>
address: 5605 apple st<br>
home phone: 555-555-5555<br>
cell phone: 555-555-5555<br>
e-mail: jane@mydomain.com<br>
<p>
|
|
|
Back to top |
|
Maxcube Smarty n00b
Joined: 28 Jul 2004 Posts: 3
|
Posted: Thu Jul 29, 2004 9:01 am Post subject: |
|
|
Danke, dies habe ich auch schon gefunden, aber leider habe ich dies nicht so recht verstanden, wie ich dies dann in PHP umsetzen/schreiben soll.. .
mfg.
Maxcube |
|
Back to top |
|
electr0n Smarty Rookie
Joined: 26 Mar 2004 Posts: 32 Location: Germany
|
Posted: Thu Jul 29, 2004 12:41 pm Post subject: |
|
|
In PHP kannst du sowas folgendermaßen anlegen:
[php:1:4906139340]<?php
$smarty_daten = array();
$query = mysql_query(...);
while ($daten = mysql_fetch_assoc($query)) {
$smarty_daten[] = $daten;
}
$smarty->assign('daten', $smarty_daten);
?>[/php:1:4906139340]
Beispielstemplate:
Code: | {foreach from=$daten item=news}
Geschrieben von {$news.autor}<br />
{$news.text}
<hr />
{/foreach} |
Diesbezüglich steht eigentlich alles in der Dokumentation. |
|
Back to top |
|
Maxcube Smarty n00b
Joined: 28 Jul 2004 Posts: 3
|
Posted: Thu Jul 29, 2004 12:45 pm Post subject: |
|
|
danke |
|
Back to top |
|
|
|
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
|