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

Using {foreach} multiple times

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


Joined: 11 Dec 2013
Posts: 1

PostPosted: Wed Dec 11, 2013 11:12 am    Post subject: Using {foreach} multiple times Reply with quote

Hello,

i have a file index.php which displays the index.tpl.
In index.tpl i load 2 more templates, for example detail.tpl and info.tpl.

index.php has a database request, fetching data and writing it into a variable called $res.

I now want to use {foreach $res as $r} in both of the templates detail.tpl and info.tpl. But only one gets displayed. When i disable info.tpl the detail.tpl is displayed and the other way around. All the code between {foreach..} and {/foreach} is not being rendered.

What am i doing wrong?

Regards
Steffen
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Wed Dec 11, 2013 2:15 pm    Post subject: Reply with quote

is $res the database result object, or an actual array of data? If its an actual array it should work just fine. example:

Code:
$res = $db->query();
while($row = $res->next())) {
  $rows[] = $row;
}
$smarty->assign('rows',$rows);
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