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

How should I use Foreach or section?

 
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
hewtluca
Smarty n00b


Joined: 16 Aug 2004
Posts: 2

PostPosted: Tue Aug 17, 2004 8:31 am    Post subject: How should I use Foreach or section? Reply with quote

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
View user's profile Send private message
dthought
Smarty Regular


Joined: 21 Apr 2003
Posts: 55
Location: Melbourne, Australia

PostPosted: Wed Aug 25, 2004 7:11 am    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message Visit poster's website
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