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

[SOLVED] Array-Pointer Reset (in {foreach})

 
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 -> General
View previous topic :: View next topic  
Author Message
uffeUtvecklare
Smarty Rookie


Joined: 23 Feb 2011
Posts: 8

PostPosted: Wed Feb 23, 2011 11:01 am    Post subject: [SOLVED] Array-Pointer Reset (in {foreach}) Reply with quote

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
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Wed Feb 23, 2011 12:38 pm    Post subject: Re: Array-Pointer Reset (in {foreach}) Reply with quote

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
View user's profile Send private message
uffeUtvecklare
Smarty Rookie


Joined: 23 Feb 2011
Posts: 8

PostPosted: Wed Feb 23, 2011 12:59 pm    Post subject: Re: Array-Pointer Reset (in {foreach}) Reply with quote

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 Embarassed

I'll mark this as solved and let this die.
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 -> General 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