|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
lesmith Smarty Rookie
Joined: 19 Sep 2003 Posts: 34
|
Posted: Thu Oct 02, 2003 9:48 pm Post subject: <tr> help |
|
|
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 |
|
muppie Smarty Rookie
Joined: 27 Apr 2003 Posts: 20
|
Posted: Fri Oct 03, 2003 7:51 am Post subject: |
|
|
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 |
|
lesmith Smarty Rookie
Joined: 19 Sep 2003 Posts: 34
|
Posted: Fri Oct 03, 2003 8:14 am Post subject: |
|
|
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 |
|
muppie Smarty Rookie
Joined: 27 Apr 2003 Posts: 20
|
Posted: Fri Oct 03, 2003 8:32 am Post subject: |
|
|
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 |
|
lesmith Smarty Rookie
Joined: 19 Sep 2003 Posts: 34
|
Posted: Fri Oct 03, 2003 3:18 pm Post subject: |
|
|
this worked SWEET thankyou for your help. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Oct 03, 2003 4:59 pm Post subject: |
|
|
...reminds me of this thread, except with rows. |
|
Back to top |
|
muppie Smarty Rookie
Joined: 27 Apr 2003 Posts: 20
|
Posted: Fri Oct 03, 2003 10:23 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
|
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
|