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

<tr> 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
lesmith
Smarty Rookie


Joined: 19 Sep 2003
Posts: 34

PostPosted: Thu Oct 02, 2003 9:48 pm    Post subject: <tr> help Reply with quote

Help Please

I have query a database and now I want to output it into a table. I know {section} does this very nice but I need more than one bit of data in a table row. ie

{section name=i loop=$list}
<tr>
<td>{$list[i].name}</td>
<td>{$list[i].name}</td>
</tr>
{/section}

I know this is incorect. It will obviously output the same data in the <td> tags before it creates another row with the second bit of data.

How can I do this please !!!
Back to top
View user's profile Send private message
muppie
Smarty Rookie


Joined: 27 Apr 2003
Posts: 20

PostPosted: Fri Oct 03, 2003 7:51 am    Post subject: Reply with quote

Hmmm sorry not to be very helpful here but you need to read the smarty intro / doc / readme... it shows you how to do this.
Back to top
View user's profile Send private message
lesmith
Smarty Rookie


Joined: 19 Sep 2003
Posts: 34

PostPosted: Fri Oct 03, 2003 8:14 am    Post subject: Reply with quote

I may be mad but I cant see it.

I can do simple queries like that. ie

{section name=i= loop=$list}
<tr>
<td>{list[i]name}</td>
<td>{list[i]address}</td>
</tr>
{/section}


But i need something like this

{section name=1 loop=$list}
<tr>
<td>{list[i]name}</td><td>{list[i]address}</td><td>{list[i]name}</td><td>{list[i]address}</td>
</tr>

So it builds something like

John | john address | mike | mike address

and so on

Hope this makes sense

Can ya help
Back to top
View user's profile Send private message
muppie
Smarty Rookie


Joined: 27 Apr 2003
Posts: 20

PostPosted: Fri Oct 03, 2003 8:32 am    Post subject: Reply with quote

Code:
{section name=i loop=$list}
{if $smarty.section.i.index is even}
<tr>
{/if}
<td>{$list[i].name}</td>
<td>{$list[i].address}</td>
{if $smarty.section.i.index is odd}
</tr>
{elseif $smarty.section.i.last}
<td>&</td><td>&</td>
</tr>
{/if}
{/section}

Might have some bug but that's get you started
Back to top
View user's profile Send private message
lesmith
Smarty Rookie


Joined: 19 Sep 2003
Posts: 34

PostPosted: Fri Oct 03, 2003 3:18 pm    Post subject: Reply with quote

this worked SWEET thankyou for your help.
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Fri Oct 03, 2003 4:59 pm    Post subject: Reply with quote

...reminds me of this thread, except with rows.
Back to top
View user's profile Send private message
muppie
Smarty Rookie


Joined: 27 Apr 2003
Posts: 20

PostPosted: Fri Oct 03, 2003 10:23 pm    Post subject: Reply with quote

Hmmm messju's code doesn't seem to add the empty <td>....</td> if the number of elements in the array is not exactly multiples of the number of columns.. I would love to see a much simpler solution though hehe

Ooops just had a look at the link in messju's post, it does padd with empty cell Smile
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