|
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 |
omexlu Smarty Rookie
Joined: 13 Mar 2014 Posts: 27
|
Posted: Mon Apr 06, 2015 7:00 am Post subject: Problem with foreach |
|
|
Hallo,
I new with smarty coding and i have some trouble
Datenbase querys
Code: | $rows4 = array();
$result4 = mysql_query("SELECT * FROM stats_follow ORDER BY id DESC LIMIT 5");
while($row4 = mysql_fetch_assoc($result4)) {
$rows4[] = $row4;
}
$rows45 = array();
$result45 = mysql_query("SELECT * FROM stats_follow ORDER BY id DESC LIMIT 5 OFFSET 1");
while($row45 = mysql_fetch_assoc($result45)) {
$rows45[] = $row45;
}
/** assign variable */
$smarty->assign('rows4', $rows4);
$smarty->assign('rows45', $rows45);
|
TPL
Code: | {foreach $rows4 as $row4}
<tr>
<td><center>{$row4.datum|truncate:10:""}</center></td>
<td><center>{$row4.count|truncate:10:""} {$row45.count}</center></td>
</tr>
{/foreach} |
But how can i assign the second query in this foreach now, this dont work:
Code: | {foreach $rows4 as $row4 || $rows45 as $row45}
<tr>
<td><center>{$row4.datum|truncate:10:""}</center></td>
<td><center>{$row4.count|truncate:10:""} {$row45.count}</center></td>
</tr>
{/foreach} |
Thanks in advance. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Apr 06, 2015 2:03 pm Post subject: |
|
|
Code: | {foreach $rows4 as $key =>$row4}
<tr>
<td><center>{$row4.datum|truncate:10:""}</center></td>
<td><center>{$row4.count|truncate:10:""} {$rows45.$key.count}</center></td>
</tr>
{/foreach} |
|
|
Back to top |
|
omexlu Smarty Rookie
Joined: 13 Mar 2014 Posts: 27
|
Posted: Tue Jan 24, 2017 12:11 pm Post subject: |
|
|
Hello,
Is it also possible to put a third query in the foreach?
If yes how?
Code: |
$rows4 = array();
$result4 = mysql_query("SELECT * FROM stats_follow ORDER BY id DESC LIMIT 5");
while($row4 = mysql_fetch_assoc($result4)) {
$rows4[] = $row4;
}
$rows45 = array();
$result45 = mysql_query("SELECT * FROM stats_follow ORDER BY id DESC LIMIT 5 OFFSET 1");
while($row45 = mysql_fetch_assoc($result45)) {
$rows45[] = $row45;
}
$rows45 = array();
$result45 = mysql_query("SELECT * FROM stats_follow ORDER BY id DESC LIMIT 5 OFFSET 2");
while($row45 = mysql_fetch_assoc($result45)) {
$rows45[] = $row45;
}
/** assign variable */
$smarty->assign('rows4', $rows4);
$smarty->assign('rows45', $rows45);
$smarty->assign('rows455', $rows455); |
Code: | {foreach $rows4 as $key =>$row4}
<tr>
<td><center>{$row4.datum|truncate:10:""}</center></td>
<td><center>{$row4.count|truncate:10:""} {$rows45.$key.count}</center></td>
<td><center {$rows455.$key.field}</center></td>
</tr>
{/foreach} |
Thanks |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Tue Jan 24, 2017 9:16 pm Post subject: |
|
|
Should work.
What's your experience trying this? |
|
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
|