what i was thinking yesterday with that order by clause worked, it's putting the permission for that realm if there are multiple on an account as the first record returned. the sql can probably be cleaned up a little more by limiting it to return only a single row but it works. testing yesterday i also added in a couple lines to make it so that you don't have to assign the account's gmlevel if you don't have any forced on the realm they're trying to log into but do on other realms. i'll be busy tonight and tomorrow as well, but i'll post the code changes on sunday for ya'll to see what i'm talking about here
having
"ON a.id = a_fp.AccountID where `username` = '%s' "
would be the correct way, the reason you'd probably be getting errors in your console over it is if someone doesn't have permissions being forced. if they don't have permissions being forced they'd just have a NULL value being returned for the 3 values that are in the account_forcepermission table and an int value can't equal NULL as you can guess. though this has no impact on data being returned.
a quick way to see what i mean, is to open up your preferred database editor (navicat, sqlyog, command line, etc) and use the following as your query:
SELECT a.id, a.gmlevel, a.sessionkey, a.last_ip, a.locked, a.v, a.s, a.expansion, a.mutetime, a.locale, a_fp.accountid, a_fp.realmID, a_fp.security FROM account as a LEFT JOIN account_forcepermission as a_fp ON a.id = a_fp.AccountId WHERE a.username = '%s' ORDER BY FIELD(a_fp.realmid,'%u') DESC
replace %s (where clause) with a username that doesn't have a forced permission in the table, and replace %u (order by clause) with an id from one of your realms. if someone has permissions being forced upon multiple realms then you can see how it will be returned by replacing the %u with a specific realm id (all that will happen is that realm's specific permissions for the user will be first in the list).