|
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 |
hewtluca Smarty n00b
Joined: 16 Aug 2004 Posts: 2
|
Posted: Tue Aug 17, 2004 8:31 am Post subject: How should I use Foreach or section? |
|
|
What I am trying to do is.... I have a page where I need to show multiple categories in one field. The problem I am having is when I get the array instead of it seperating the rows i.e. id 1 has 2 cats and id 2 has 7 cats.....it is printing them all out in both id's.
My code for getting the info is
Code: |
$articles_array = mysql_db_query($config['db']['name'],"select * from ".$config['db']['prefix']."articles where cat_sort = 'featured' order by date desc", $verbinding)or die("aaaaaa");
$art_id[] = $articles['a_id'];
$cate_array = mysql_db_query($config['db']['name'],"select * from articles_cat where a_a_id = '$articles[a_id]'", $verbinding)or die("abbbb");
$c_cat_name[]=$cate['sub_cat_name'];
|
and my output in the template is
Code: |
{section name=latest loop=$art_date}
<tr>
<td width="31%"><strong>{$art_title[latest]}</strong></td>
<td width="10%"><div align="center">{$art_bids[latest]}</div></td>
<td width="25%">{section name=cat loop=$c_cat_name}{$c_cat_name[cat]}, {/section}</td>
<td width="20%"><div align="center">{$art_date[latest]}</div></td>
<td width="14%"><div align="center">{$art_end_date[latest]}</div></td>
</tr>
{/section}
|
When I try nested sections such as
Code: |
{section name=latest loop=$art_date}
<tr>
<td width="31%"><strong>{$art_title[latest]}</strong></td>
<td width="10%"><div align="center">{$art_bids[latest]}</div></td>
<td width="25%">{section name=cat loop=$c_cat_name [latest]}{$c_cat_name[latest][cat]}, {/section}</td>
<td width="20%"><div align="center">{$art_date[latest]}</div></td>
<td width="14%"><div align="center">{$art_end_date[latest]}</div></td>
</tr>
{/section}
|
Nothing is printed out.
Everything on my site works fine, but the cats.....any sugestions? |
|
Back to top |
|
dthought Smarty Regular
Joined: 21 Apr 2003 Posts: 55 Location: Melbourne, Australia
|
Posted: Wed Aug 25, 2004 7:11 am Post subject: |
|
|
Put in a {debug output='html'} into your TPL file. If the keys are not 0, 1, 2, 3 etc. within your result variable, you'll need to use a {foreach} instead of a {section}. Annoyingly, the notation for foreach is quite different to section, but is still perfectly usable |
|
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
|