Your table setup for `rpguserabilities` is a bit ackward.
You have the field called `checked`, although shouldn't it be implicit that a user has an ability simply if the row exists? (since the row contains the ability name) ?
If I were you, I'd make the `rpguserabilities`contain the ability name for a field, but also the ability id (or just the ability id, incase you ever change the ability name you wouldn't want to have to update every row), and drop the `checked`.
Then you could use the following.
PHP Code:
$abilities = $DB_site->query("
SELECT abid, name, description
FROM `abilities`");
$user = $DB_site->query_first("
SELECT id, username, name, abid, abexp
FROM `userabilities`
WHERE id=$bbuserinfo[userid]");
while ($ability = $DB-site->fetch_array($abilities))
{
if ($user['abid'] == $ability['abid'])
{
$is_checked = ' checked="checked"'; // to be used in template
// or substitute a template:
// eval('$is_checked = "'.fetch_template('template_is_checked') . '";');
}
eval('$option_row .= "'.fetch_template('template_option_row') . '";');
// this template contains the checkbox input information (name, description),
// and the $is_checked variable
unset($is_checked); // make sure to delete $is_checked
}
eval("dooutput(\"".gettemplate('template_options')."\");");
// output main template