using template in a loop
techu Offline
Member
***
Posts: 154
Joined: Sep 2010
Post: #1
using template in a loop
I am trying to making a new page in mybb. I am new to this so i am not sure how to use template in a loop.

Code:
while($var = $db->fetch_array($query))
{
echo $var[gid]."<br/>";
echo $var[name];
}

The above code obviously works.. and it returns something like:

Quote:1 name
2 name2

but if I do:

Code:
while($var = $db->fetch_array($query))
{
eval("\$group_bit= \"".$templates->get("social_group_bit")."\";");
}


And the template code is:

Code:
{$var[gid]}<br/>
{$var[name]}


In this case it returns the only last value  that is:

Quote:2 name2

I am not sure how to use the templates in this case properly.

[Image: banner.png]
(This post was last modified: 04-19-2011 01:16 PM by techu.)
04-19-2011 01:16 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: using template in a loop
Of course, because you're using =, you're overwriting the variable on each loop cycle.
Consider

PHP Code:
$a = 1;
$a = 2;

The first line may as well not be there because it's overwritten by the second.

You probably want to use the string concatenation operator (.=) not the assign operator (=).


My Blog
04-19-2011 02:42 PM
Find all posts by this user Quote this message in a reply
techu Offline
Member
***
Posts: 154
Joined: Sep 2010
Post: #3
RE: using template in a loop
(04-19-2011 02:42 PM)ZiNgA BuRgA Wrote:  Of course, because you're using =, you're overwriting the variable on each loop cycle.
Consider

PHP Code:
$a = 1;
$a = 2;

The first line may as well not be there because it's overwritten by the second.

You probably want to use the string concatenation operator (.=) not the assign operator (=).

I knew that the value is getting overwritten but not sure how to solve it.

Using (.=) in eva ("\$group_bit .= \"".$templates->get("social_group_bit")."\";"); worked nicely..

Thanks..

[Image: banner.png]
04-19-2011 04:44 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: