Not Solved Database queries.
#1
Not Solved
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.
Reply
#2
Not Solved
can you tell us what exactly you want to get from the database ..
Reply
#3
Not Solved
(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.
Reply
#4
Not Solved
here is a simple example php file to get user groups names & their IDs
<?php

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

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

// OUTPUT
echo $groups;

see Database Methods guidance
Reply
#5
Not Solved
^ 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?
Reply
#6
Not Solved
it would be better to create a plugin & make required variable global by using a global hook.

* plugin basics | * database methods | * plugin hooks
* guidance on plugins making | * plugins & hooks explained | * Plugin Authoring For Beginners
* How to make a plugin | * quick tutorial on plugins making
* advanced plugin development
Reply
#7
Not Solved
^ 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.
Reply
#8
Not Solved
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 !
Reply
#9
Not Solved
$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.
Reply
#10
Not Solved
you need to eval this variable to use it in the template system
Paid support or developement: www.broatcast-consulting.de
All other: blog.broatcast.de

[Image: EbbMWfN.png]

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)