MyBB Community Forums

Full Version: Database queries.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hey guys.

I have been using MyBB a lot since the last two years but I haven't yet done anything with Database but today I need to. I'm clueless here and would love some assistance.

The thing is I need to pull some data from a TABLE that is in the same database as my FORUM.

I need to display all that data later in user profiles. So as far as my guess goes I'll have to make a query in the member.php file.

If anyone could provide me with some help or example I'll be eternally gratefully.

Cheers and regards.
can you tell us what exactly you want to get from the database ..
(2017-05-01, 11:06 AM).m. Wrote: [ -> ]can you tell us what exactly you want to get from the database ..

Just a few records to display that are stored in another table. I have created a new page to display the data. So I should add the queries in the PHP file of the new page right?

Can you provide me with an example query. I would like to fetch data from a table that is in the same database as my forum one.
here is a simple example php file to get user groups names & their IDs

define('IN_MYBB', 1);
require_once "./global.php";

	$query = $db->simple_select("usergroups", "*", "");
	$sep = "";
	while($group = $db->fetch_array($query))
		$groupname = $group['title'];
		// GID
		$gid = $group['gid'];
		$groups .= "{$sep} [ {$gid} ] &rarr; {$groupname}";
		$sep = "<br />";

echo $groups;

see Database Methods guidance
^ Thanks for that not exactly what I wanted but it does help.

Another question suppose I have a query. How will I save the output of that query into a global variable and use it wherever I require?
^ No that isn't gonna help sorry. Making a plugin just to pull a few records is way too much work.

I'm able to pull data now but I just don't know how to store the data of the query in a variable and use it on the same page.
your file need not be a pure plugin but plugin hook needs to be used & file needs to be added to plugins folder

though made for a different purpose, see attachment here for the display method !
$query = $db->query("SELECT username from housing");
	while($result = $db->fetch_array($query))
        $housingvar .= "Adress: " . $result["Adress"]. ;
		return $housingvar;


I'm using the variable $housingvar in the template but no return value. However this does seem to work if I use echo.
you need to eval this variable to use it in the template system
Pages: 1 2