MyBB Community Forums

Full Version: Custom Page - Perform SQL Query
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a custom page setup, loading the page data from a template (this can be changed if needed). How can I go about running an SQL query? I have PHP in Templates but that doesn't seem to support queries.

What's the easiest way to do this?

EDIT: I tinkered for 2 hours before posting this, and just finally found the answer 2 minutes after posting.

I put the whole template into the PHP page directly, and just used output_page("{$header"); for the variables like that. Smile
You don't need to paste the template in the php file Confused

Just replicate what MyBB does, define your variables and use them in the template:
$query = $db->simple_select('users', 'username', "uid=''{$mybb->user['uid']}");
$username = $db->fetch_field($query, 'username');
$username or ($username = 'Guest');
eval('$page = "'.$templates->get('my_tmpl').'";');

my_tmpl content:
Hi {$username}!