Topic: Forums moderators
How are the moderators' IDs stored for each forum?
Let's say I want to retrieve the moderators for forum with ID 10, where should I look at?
TIA.
You are not logged in. Please login or register.
PunBB Forums → PunBB 1.2 modifications, plugins and integrations → Forums moderators
How are the moderators' IDs stored for each forum?
Let's say I want to retrieve the moderators for forum with ID 10, where should I look at?
TIA.
They're stored in serialized form in the moderators column in the forums table.
The code in index.php to unserialize is:
$mods_array = unserialize($cur_forum['moderators']);
while (list($mod_username, $mod_id) = @each($mods_array))
Thanks svl.
I have problem now.
I'm trying to put the query into a function
so I have
$fid = some number
$result = $db->query('SELECT moderators FROM '.$db->prefix.'forums WHERE id = '.$fid) or die();
if($db->num_rows($result))
{
while ($cur_forum = $db->fetch_assoc($result))
{
$mods_array = unserialize($cur_forum['moderators']);
$moderators = array();
while (list($mod_username) = @each($mods_array))
$moderators[] = pun_htmlspecialchars($mod_username);
$moderators = '<p>'.implode(', ', $moderators).'</p>'."\n";
}
echo $moderators;
}
And it works
but if I try to make it a function, like this:
function get_mods($fid)
{
$result = $db->query('SELECT moderators FROM '.$db->prefix.'forums WHERE id = '.$fid) or die();
if($db->num_rows($result))
{
while ($cur_forum = $db->fetch_assoc($result))
{
$mods_array = unserialize($cur_forum['moderators']);
$moderators = array();
while (list($mod_username) = @each($mods_array))
$moderators[] = pun_htmlspecialchars($mod_username);
$moderators = '<p>'.implode(', ', $moderators).'</p>'."\n";
}
echo $moderators;
}
}
get_mods("some number");
I get this error
Fatal error: Call to a member function query() on a non-object in... etc.
Any hint?
You need to learn about variable scoping in PHP. A variable like $db declared outside a function isn't available (by default) inside the function.
The fix is to do this:
function get_mods($fid)
{
$db = $GLOBALS['db'];
$result = $db->query('SELECT moderators FROM '.$db->prefix.'forums WHERE id = '.$fid) or die();
To keep it in sync with the rest of the PunBB code, that line:
$db = $GLOBALS['db'];
would be:
global $db;
Sweet, thanks a lot both of you.
PunBB Forums → PunBB 1.2 modifications, plugins and integrations → Forums moderators
Powered by PunBB, supported by Informer Technologies, Inc.