Welcome to WebmasterWorld Guest from 3.227.208.153

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

php and smarty

section loop smarty php

     
1:21 pm on Jul 21, 2011 (gmt 0)

New User

5+ Year Member

joined:July 21, 2011
posts: 3
votes: 0


Hello, I'm having a problem calling a loop using smarty from php. Here's the code I'm working on:


for($k=1;$k<=$score;$k++){

echo '<div class="enab" id="'.$k.'">&nbsp;</div>';

}


for($i=$rem;$i>=1;$i--){

echo '<div class="dis" id="'.$k.'">&nbsp;</div>';

}

$k++;

$smarty->assign('score',?);
$smarty->assign('score2',?);


I need to make them both loop in smarty, one on top of the other.
so they will make a list like so:

<div class="enab" id="1">&nbsp;</div>
<div class="enab" id="2">&nbsp;</div>
<div class="enab" id="3">&nbsp;</div>
<div class="dis" id="4">&nbsp;</div>
<div class="dis" id="5">&nbsp;</div>


using something like (in template tpl):

{section name=score loop=$score}
{$score[score]}
<br />
{/section}

I cannot seem to get it to loop the php 'for' query. Can Anyone shed any light on this?

Thank You.
2:10 pm on July 21, 2011 (gmt 0)

New User

5+ Year Member

joined:July 21, 2011
posts: 3
votes: 0


I could assign:

$smarty->assign('score',$score);
$smarty->assign('rem',$rem);

but how can I loop them?

or...

How can I make:

for($i=$rem;$i>=1;$i--){
$b .= '<div>blah blah blah</div>';
}

an array?
9:05 pm on July 21, 2011 (gmt 0)

New User

5+ Year Member

joined:July 21, 2011
posts: 3
votes: 0


ok, I have decided to just kill it with fire.
2:40 pm on July 23, 2011 (gmt 0)

Full Member

10+ Year Member

joined:June 1, 2007
posts:201
votes: 0


Do your work in php and pass an array to the Smarty tpl.

{foreach item="item" from=$item_array}
<div id="{$item.count"}">{$item.item}</div>
{/foreach}