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

HELP ; PHP TO SMARTY

 
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 Oct 16, 2014 3:37 pm    Post subject: HELP ; PHP TO SMARTY Reply with quote

Hello

i have a test page php 1.php with this code
Code:

<?php
$shows = $show->getShows(null,$default_language);
$shows = $misc->aasort($shows,"title");
?>
 
 
                    <label class="control-label">TV show</label>
                    <div class="controls">
                         <select name="show_id" id='show_id' onchange="reloadEpisode();" class="span3" >
                             <option value='0'>Select a show</option>
                              <?php
                                if (count($shows)){
                                    foreach($shows as $id => $val){
                                        $show_title = stripslashes($val['title']);
                                        print("<option value='$id' "); if (isset($show_id) && $show_id==$id) print(" selected='selected'"); print(">$show_title</option>\n");
                                    }
                                }
                              ?>
                         </select>
                         </div>


i wanna try to get 1.php with this code
Code:

<?php
$shows = $show->getShows(null,$default_language);
$shows = $misc->aasort($shows,"title");
?>


and 1.tpl
Code:

<label class="control-label">TV show</label>
                    <div class="controls">
                         <select name="show_id" id='show_id' onchange="reloadEpisode();" class="span3" >
                             <option value='0'>Select a show</option>
                              {foreach from=$show_title item=show_id key=id}
                    <option value="{$id}"{if $show_id eq $id} selected="selected"{/if}>{$show_title}</option>
                {/foreach}
                         </select>
                         </div>
Back to top
View user's profile Send private message
spaindre
Smarty Rookie


Joined: 16 Oct 2014
Posts: 7

PostPosted: Thu Oct 16, 2014 4:27 pm    Post subject: Reply with quote

BUT it's not working any help pls
Back to top
View user's profile Send private message
kowach
Smarty Rookie


Joined: 26 Jan 2011
Posts: 13

PostPosted: Fri Oct 17, 2014 1:34 pm    Post subject: Reply with quote

You are doing it wrong. Why don't you prepare show options?

1.php
Code:

// concat two arrays
$show_options  = array( 0 => "Select a show");
foreach($shows as $id => $val)
    $show_options [$id]=  stripslashes($val['title']);
                                       
$smarty->assign('show_options',$show_options);
$smarty->assign('show_id',$show_id);


1.tpl - nice and clean
Code:

<label class="control-label">TV show</label>
<div class="controls">
{html_options name="show_id" id="show_id" onchange="reloadEpisode();" class="span3" options=$shows_options selected=$show_id}
</div>
</label>


http://www.smarty.net/docsv2/en/language.function.html.options.tpl
Back to top
View user's profile Send private message
spaindre
Smarty Rookie


Joined: 16 Oct 2014
Posts: 7

PostPosted: Fri Oct 17, 2014 9:19 pm    Post subject: Reply with quote

perfect thank you very much
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