Re: [SMARTY] sections and associative arrays

From: Date: Fri, 19 Dec 2003 11:46:00 +0000
Subject: Re: [SMARTY] sections and associative arrays
References: 1 2 3  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10728@lists.php.net to get a copy of this message
On Fri, Dec 19, 2003 at 11:19:51AM -0000, Alexander Gabriel wrote: > Thanks for your prompt reply. > This is what i've done in Example 4. Doh'! I didn't read that far :) > I didn't know, section cannot handle associative arrays. I'll use foreach > instead. > > Have a nice weekend > > Alexander Gabriel > > On 19 Dez 2003, you wrote in php.smarty.general: > > > > > {section} does not work with associcitive arrays. you need {foreach} > > for that. > > > > Example 2 > > <table> > > {section name=MyRow loop=$MyValues} > > <tr> > > {foreach key=MyColumn item=MyValue from=$MyValues[MyRow]} > > <td>{$MyValues[MyRow].$MyColumn}</td> > > or simply > > <td>{$MyValue}</td> > > {/section} > > </tr> > > {/section} > > </table><br><br> > > > > HTH > > messju > > > > On Fri, Dec 19, 2003 at 10:23:31AM -0000, Alexander Gabriel wrote: > >> Hi group, > >> > >> now, i think, i'm on the right list :) > >> > >> you can see i've got a problem with associative arrays in smarty. > >> I've tried Andreas' hint, too but it doesn't work. If ID is numeric > >> and e.g. 50000, Smarty does 50000 loops. > >> > >> Here are 4 Examples. 1 and 4 are working, 3 is the one with the 50000 > >> loops and the question is, why Example 2 is not working. > >> > >> [code] > >> Example 1 > >> <table> > >> {section name=MyRow loop=$MyValues} > >> <tr> > >> <td>{$MyValues[MyRow].ID}: {$MyValues[MyRow].Bezeichnung} > >> </td> > >> </tr> > >> {/section} > >> </table><br><br> > >> > >> Example 2 > >> <table> > >> {section name=MyRow loop=$MyValues} > >> <tr> > >> {section name=MyColumn loop=$MyValues[MyRow]} > >> <td>{$MyValues[MyRow][MyColumn]}</td> > >> {/section} > >> </tr> > >> {/section} > >> </table><br><br> > >> > >> Example 3 > >> <table> > >> {section name=MyRow loop=$MyValues} > >> <tr> > >> {section name=MyColumn loop=$MyValues[MyRow].ID} > >> <td>{$MyValues[MyRow][MyColumn]}</td> > >> {/section} > >> </tr> > >> {/section} > >> </table><br><br> > >> > >> Example 4 > >> <table> > >> {section name=MyRow loop=$MyValues} > >> <tr> > >> {foreach item=MyColumn from=$MyValues[MyRow]} > >> <td>{$MyColumn}</td> > >> {/foreach} > >> </tr> > >> {/section} > >> </table> > >> [/code] > >> > >> It would be very nice, if someone could help me > >> > >> thx > >> Alexander Gabriel > >> > >> > >> >Hi, > >> > > >> >This ist the wrong mailing list. Smarty has ist own. > >> > > >> >Nevertheless yout second example is not really ok. > >> >You must set a variable in the loop of the second section (e.g. > >> >loop=$MyValues[MyRow].ID ) > >> > > >> > > >> >Andreas Otterstein > >> > > >> > > >> >-----Ursprüngliche Nachricht----- > >> >Von: Alexander Gabriel [mailto:alexander.gabriel@blubbermania.com] > >> >Gesendet: Freitag, 19. Dezember 2003 10:33 > >> >An: pear-general@lists.php.net > >> >Betreff: [PEAR] sections and associative arrays > >> > > >> > > >> >Hi group, > >> > > >> >i've got a problem with an associative array. > >> > > >> >if i'm doing: > >> > > >> >[code] > >> ><table> > >> >{section name=MyRow loop=$MyValues} > >> > <tr> > >> > <td>{$MyValues[MyRow].ID}: > >> >{$MyValues[MyRow].Bezeichnung}</td> > >> > </tr> > >> >{/section} > >> ></table> > >> >[/code] > >> > > >> >i get a table with the values 'ID' and 'Bezeichnung' from my > >> >SQL-result. > >> > > >> > > >> >according to the documentation chapter 7, exapmle 19, this should > >> >work too: > >> > > >> >[code] > >> ><table> > >> >{section name=MyRow loop=$MyValues} > >> > <tr> > >> > {section name=MyColumn loop=$MyValues[MyRow]} > >> > <td>{$MyValues[MyRow][MyColumn]}</td> > >> > {/section} > >> > </tr> > >> >{/section} > >> ></table> > >> >[/code] > >> > > >> >but all i get is the same table as above but without any values. > >> > > >> >I'm new to Smarty and maybe this is just a beginners mistake. would > >> >be really nice if you could help me. > >> > > >> >thx > >> >Alexander Gabriel > >> > > >> >-- > >> >PEAR General Mailing List (http://pear.php.net/) > >> >To unsubscribe, visit: > >> >http://www.php.net/unsub.php > >> > >> -- > >> Smarty General Mailing List (http://smarty.php.net/) > >> To unsubscribe, visit: http://www.php.net/unsub.php > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.smarty.general (#10728) next »