MyBB Community Forums

Full Version: How to store multiple values in a variable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
What I have is a system that finds the users last 5 stored entries, and then echoes them back to the user, like this:

$query = $db->query("SELECT imagename from ".TABLE_PREFIX."tablename WHERE `uid` = {$mybb->input['uid']} ORDER BY dateline DESC Limit 0,5");
		
while ($row = $db->fetch_array($query, 'imagename')) {
$rows = $row["imagename"];
echo $rows . "<br />";
}

That works perfectly, by displaying the values on top of the mybb page. I'm curious as to how to place that data (of the 5 rows itself) in the template system. Instead what occurs when I place {$rows} is the first value is displayed independently, which is not what's meant to happen.
You'd better use this syntax:

$query = $db->query("SELECT imagename from ".TABLE_PREFIX."tablename WHERE `uid` = {$mybb->input['uid']} ORDER BY dateline DESC Limit 0,5");

$rows = "";

while ($row = $db->fetch_array($query, 'imagename')) {
$rows .= $row["imagename"];
}

echo $rows;

Notice the use of .= operator which adds a piece of data every time the while loop evaluates to true.

With more complex data you should make use of arrays instead.
Works perfectly, thanks man. It's better than my other method that was working, even though the queries were identical (and the loading time).