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

Problem with foreach

 
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
omexlu
Smarty Rookie


Joined: 13 Mar 2014
Posts: 27

PostPosted: Mon Apr 06, 2015 7:00 am    Post subject: Problem with foreach Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Apr 06, 2015 2:03 pm    Post subject: Reply with quote

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


Joined: 13 Mar 2014
Posts: 27

PostPosted: Tue Jan 24, 2017 12:11 pm    Post subject: Reply with quote

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


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Tue Jan 24, 2017 9:16 pm    Post subject: Reply with quote

Should work.

What's your experience trying this?
Back to top
View user's profile Send private message
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