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

looping through <tr><td><

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


Joined: 28 Apr 2003
Posts: 9

PostPosted: Tue Apr 29, 2003 8:44 pm    Post subject: looping through <tr><td>< Reply with quote

I have a table i want to populate from an array but i can't think how to do it.

Code:

pseudo code:
<table>
{section name=loop id=$id}
<tr>
    <td width="50%">{$var[loop]}</td>
    <td width="50%">{$var[loop]}</td>
</tr>
{/section}
</table>

---------------------------
required output:

<table>
<tr>
    <td width="50%">1</td>
    <td width="50%">2</td>
</tr>
<tr>
    <td width="50%">3</td>
    <td width="50%">4</td>
</tr>
<tr>
    <td width="50%">5</td>
    <td width="50%">6</td>
</tr>
</table>


i'm sure this is the kind of thing i need but it has to increment the id variable twice per loop as you can see in the output.

any help is much appreciated


Last edited by ciqala on Wed May 05, 2010 10:41 pm; edited 1 time in total
Back to top
View user's profile Send private message
andre
Smarty Pro


Joined: 23 Apr 2003
Posts: 164
Location: Karlsruhe, Germany

PostPosted: Tue Apr 29, 2003 9:31 pm    Post subject: Reply with quote

Have a look at {html_tables} of Smarty 2.5.0. Also search the Wiki for it. I think you'll find your answer there Wink
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Tue Apr 29, 2003 9:59 pm    Post subject: Reply with quote

{section} http://smarty.php.net/manual/en/language.function.section.php supports an step value:

{section name=loop id=$id step=2}
<tr>
<td width="50%">{$var[loop]}</td>
{math equation="x + 1" x=$loop assign=partner}
<td width="50%">{$var[partner]}</td>
</tr>
{/section}
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Apr 29, 2003 10:19 pm    Post subject: Reply with quote

I would avoid {math} calls, especially in section loops. It uses eval() which isn't so efficient.

Use the solution in the wiki, or {html_table} for simple loops.

Monte
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Tue Apr 29, 2003 10:28 pm    Post subject: Reply with quote

OOPS. I didn't mean to post that message. I realized that it wouldn't work out well as I was writing it and I thought I aborted it. Sorry, please ignore.
Back to top
View user's profile Send private message
ciqala
Smarty Rookie


Joined: 28 Apr 2003
Posts: 9

PostPosted: Wed Apr 30, 2003 8:01 am    Post subject: Reply with quote

Rolling Eyes of course, I shoulda RTFM Very Happy

Thanks guys
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