You need to escape reserved words in MySQL like group
with backticks
SELECT * FROM members WHERE `group` = '$g_id'
^-----^-------------here
You can also spare the inner loop when you join your data like this
select g.id as gid, g.g_name, m.id as mid, m.m_name, m.m_email
from groups g
inner join members m on g.id = m.group
order by g.id asc
This is easier and will increase performance since you don't need to execute a lot of queries but just one.
Also please don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. Learn about Prepared Statements instead, and use PDO or MySQLi. See this article for a quick overview how to do it and why it is so important.