|
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 |
uffeUtvecklare Smarty Rookie
Joined: 23 Feb 2011 Posts: 8
|
Posted: Wed Feb 23, 2011 11:01 am Post subject: [SOLVED] Array-Pointer Reset (in {foreach}) |
|
|
I have been looking around like a madman(atleast my boss seems to think so ;) ) after a way to reset the array pointer after foreach'ing thru an array after the first, of many, times. Been searching the forums but haven't been able to find anyone with this exact problem.
Anyone who wants to point me in the right direction? I'm using smarty 2.6.14(and please dont ask why).
The part I'm pasting is just going thru all the categories to see wich ones are checked. This is the code:
[code]
{foreach from="$categories" item="category"}
{foreach from="$selectedCategories" item="selectedCategory"}
{if in_array($category[0], $selectedCategory)}
{assign var="selected" value=" checked=\"true\""}
{else}
{assign var="selected" value=""}
{/if}
{/foreach}
{/foreach}
[/code]
Last edited by uffeUtvecklare on Wed Feb 23, 2011 12:59 pm; edited 1 time in total |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Wed Feb 23, 2011 12:38 pm Post subject: Re: Array-Pointer Reset (in {foreach}) |
|
|
I'm not sure what you mean by resetting the pointer, but the "from" attribute variable names don't belong in quotes.
Code: |
{foreach from=$categories item="category"}
{foreach from=$selectedCategories item="selectedCategory"}
{if in_array($category[0], $selectedCategory)}
{assign var="selected" value=" checked=\"true\""}
{else}
{assign var="selected" value=""}
{/if}
{/foreach}
{/foreach}
|
|
|
Back to top |
|
uffeUtvecklare Smarty Rookie
Joined: 23 Feb 2011 Posts: 8
|
Posted: Wed Feb 23, 2011 12:59 pm Post subject: Re: Array-Pointer Reset (in {foreach}) |
|
|
douglassdavis wrote: | I'm not sure what you mean by resetting the pointer, but the "from" attribute variable names don't belong in quotes.
Code: |
{foreach from=$categories item="category"}
{foreach from=$selectedCategories item="selectedCategory"}
{if in_array($category[0], $selectedCategory)}
{assign var="selected" value=" checked=\"true\""}
{else}
{assign var="selected" value=""}
{/if}
{/foreach}
{/foreach}
|
|
Thanks for pointing that out! Ofcourse it all came down to my own stupidity. The symptoms all pointed to an array pointer not resetting itself before going in for "round 2".
Great first post
I'll mark this as solved and let this die. |
|
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
|