|
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 |
ephiance Smarty n00b
Joined: 11 Dec 2013 Posts: 1
|
Posted: Wed Dec 11, 2013 11:12 am Post subject: Using {foreach} multiple times |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Dec 11, 2013 2:15 pm Post subject: |
|
|
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 |
|
|
|
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
|