MyBB Hacks

Full Version: using template in a loop
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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 (=).

(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..
Reference URL's