View Full Version : SQL Query in profile tab
TriggerHappy123
01-02-2009, 11:11 PM
I made a plugin to add a new tab to a users profile, how would i make the data thats shown in the tab be from an executed MySQL Query?
class vB_ProfileBlock_MyModification extends vB_ProfileBlock
{
var $template_name = 'memberinfo_block_mymodification';
function confirm_empty_wrap()
{
return false;
}
function confirm_display()
{
return ($this->block_data['mymodification'] != '');
}
function prepare_output($id = '', $options = array())
{
$this->block_data['mymodification'] = 'QUERY HERE'; // what would i do here
}
}
Dismounted
01-03-2009, 03:30 AM
The DB object can be called inside the class using $this->registry->db.
TriggerHappy123
01-03-2009, 04:23 AM
Sorry i'm a php noob. A simple example using my code?
Dismounted
01-03-2009, 05:25 AM
If you do not know PHP - I doubt any examples are going to help, dealing with SQL and the like is a bit further down the track. I would suggest you learn PHP as best you can before dealing with vBulletin.
Lynne
01-03-2009, 04:34 PM
You would put the query inside the function prepare_output. You would not put it in "$this->block_data['mymodification']" as that should contain the html to output. You would do the query as Hanson suggestion, then get the results and put it in the block_data.
TriggerHappy123
01-04-2009, 09:39 PM
If you do not know PHP
I never said that, im a noob in php. I can write scripts and i have dealt with using databases before. I just need an example on how to do it with vbulletin, and it's weird template system.
Lynne
01-04-2009, 09:47 PM
You would do something like this:
function prepare_output($id = '', $options = array())
{
$subres = $this->registry->db->query_read("SELECT STATEMENT HERE");
$result = $this->registry->db->fetch_array($subres);
$this->block_data['mymodification'] = 'HTML OUTPUT';
}
TriggerHappy123
01-04-2009, 10:04 PM
Thanks, will try it out. I would +rep you only vb.org doesn't have rep :mad:
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.