It could be done with a single SQL statement. If you assume a variable EXTEN has the extension of the FOP2 user:
(select * from fop2buttons
where `group` in (select `group` from fop2buttons where exten="148") and type="extension"
order by exten)
union
(select * from fop2buttons
where `group` not in (select `group` from fop2buttons where exten="148") and type="extension"
order by `group`,exten)
The first select gets the users in the same group and as there is only one group, it only has to sort by exten. The second selection gets all the extensions not in the same group as the current FOP2 and sorts them by the group name then the exten.
Ted