Re: [SMARTY] {section} with array that doesnt start with index 0
| From: | Roman Neuhauser | Date: | Mon, 19 Aug 2002 07:40:00 +0000 |
| Subject: | Re: [SMARTY] {section} with array that doesnt start with index 0 | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5751@lists.php.net to get a copy of this message | ||
> From: "Peter Billen" <peter@clueless.be>
> To: "'Smarty General'" <smarty-general@lists.php.net>
> Date: Sun, 18 Aug 2002 22:19:32 +0200
> Subject: [SMARTY] {section} with array that doesnt start with index 0
> In my database, I have a list of gametypes. My first gametype has number
> 1, my second number 2, etc..
>
> Uptill now, I used to have the {foreach} construction to display the
> gametypes, and that worked perfectly.
>
> But with the {foreach} loop, I had some layout errors: after every loop
> I print a "<br>" (or something else). But I don't want that when the
> foreach ends (so at the last loop). Since foreach doesn't support "{if
> $smarty.section.games.last <> true}", I had to convert my foreach into a
> section.
> This works, however not for 100%. The problem is that the section
> forgets one loop. After some debugging, I tried to change to give last
> gametype index 0, instead of 13, and it worked perfectly.
>
> However, changing the primary keys of my gametypes in my dbase into a
> non-standard value (prim. keys start with 1, not with 0) is no option,
> so I need another solution to fix this.
>
> Does anyone have an idea?
this should be in the FAQ (if there's one):
{foreach} is a wrapper for foreach ()
{section} is a wrapper for for ()
iow, use array_values() before you pass the array to smarty, and put
the key elsewhere in the (sub)array
--
FreeBSD 4.6-STABLE
9:36AM up 9 days, 21:31, 19 users, load averages: 0.02, 0.01, 0.00