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

2 foreach help

 
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
spaindre
Smarty Rookie


Joined: 16 Oct 2014
Posts: 7

PostPosted: Thu Apr 30, 2015 4:37 pm    Post subject: 2 foreach help Reply with quote

Hello all

i'm newbie in smarty so i wanna ask help in foreach

this is my problem

i have 2 foreach

Code:

{foreach from=$show_options  item=show_options key=imdb_url}
<option value="{$show_options.imdb_url}" id="{$submit_data.imdb_url}" >{$show_options.title}</option>
{/foreach}


and
Code:

{foreach from=$em_languages item=em_lang key=em_key}
<option value="{$em_key}"{if $submit_data.em_language eq $em_key} selected="selected"{/if}>{$em_lang.language}</option>
{/foreach}


i have 2 value in $em_key A and B
so what i wanna get
when user shoose option B on submit i wanna get
value="{$show_options.imdb_url}X"
like that
Code:

{foreach from=$show_options  item=show_options key=imdb_url}
<option value="{$show_options.imdb_url}X" id="{$submit_data.imdb_url}" >{$show_options.title}</option>
{/foreach}


thank you
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Fri May 01, 2015 3:08 pm    Post subject: Reply with quote

May be something like this
Code:
{foreach from=$show_options  item=show_options key=imdb_url}
<option value="{$show_options.imdb_url}{$submit_data.em_language}" id="{$submit_data.imdb_url}" >{$show_options.title}</option>
{/foreach}
Back to top
View user's profile Send private message
spaindre
Smarty Rookie


Joined: 16 Oct 2014
Posts: 7

PostPosted: Mon May 04, 2015 12:00 pm    Post subject: Reply with quote

U.Tews wrote:
May be something like this
Code:
{foreach from=$show_options  item=show_options key=imdb_url}
<option value="{$show_options.imdb_url}{$submit_data.em_language}" id="{$submit_data.imdb_url}" >{$show_options.title}</option>
{/foreach}


Dont work
Sad
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon May 04, 2015 4:30 pm    Post subject: Reply with quote

Of course it won't work.
You're overriding foreach variable on first round.
Code:
{foreach $show_options  as $option}
<option value="{$option.imdb_url}{$submit_data.em_language}" id="{$submit_data.imdb_url}" >{$option.title}</option>
{/foreach}

Also, I'm not sure you understand, what id attribute is.
Back to top
View user's profile Send private message
spaindre
Smarty Rookie


Joined: 16 Oct 2014
Posts: 7

PostPosted: Tue May 05, 2015 10:29 am    Post subject: Reply with quote

AnrDaemon wrote:
Of course it won't work.
You're overriding foreach variable on first round.
Code:
{foreach $show_options  as $option}
<option value="{$option.imdb_url}{$submit_data.em_language}" id="{$submit_data.imdb_url}" >{$option.title}</option>
{/foreach}

Also, I'm not sure you understand, what id attribute is.


Hello
thank you for your reply ,
i explain what i need , in submit they are 2 option to select (show_options and $em_languages)
$em_languages have Only 2 option A and B

on submit if em_languages eq B
i wanna get in result
Code:
value="{$show_options.imdb_url}X"

and not
Code:
value="{$show_options.imdb_url}"
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue May 05, 2015 12:45 pm    Post subject: Reply with quote

Show the code. I don't understand your narrations.
Back to top
View user's profile Send private message
spaindre
Smarty Rookie


Joined: 16 Oct 2014
Posts: 7

PostPosted: Wed May 06, 2015 3:02 pm    Post subject: Reply with quote

U.Tews wrote:
May be something like this
Code:
{foreach from=$show_options  item=show_options key=imdb_url}
<option value="{$show_options.imdb_url}{$submit_data.em_language}" id="{$submit_data.imdb_url}" >{$show_options.title}</option>
{/foreach}


Thank you very much its work

i have just to move </div> under the second foreach
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