I have written this bit of code for the latest posts to display on my portal. I have written a different query for each member group so that different forums are available to each but I have to remeber to change it whenever I add or remove forums. I want it to go from the read_perms value of the ib_beta_forums but all the member groups that can view the forum are contained in the same data cell seperated by commas and I tried using leftjoin to associate the members table, the groups table and the forums table but the query wasn't working
if ( $member['group_id'] == 4 ) { //admin
$ipb_query = mysql_query("SELECT DISTINCT t.tid, t.title, t.last_poster_name, t.last_poster_id, t.starter_id, t.starter_name, t.forum_id, f.read_perms FROM ".$ipb_table_prefix."topics t INNER JOIN ".$ipb_table_prefix."forums f ON t.forum_id = f.id where t.forum_id = 1 or t.forum_id = 2 or t.forum_id = 30 or t.forum_id = 58 or t.forum_id = 45 or t.forum_id = 3 or t.forum_id = 10 or t.forum_id = 33 or t.forum_id = 38 or t.forum_id = 50 or t.forum_id = 55 or t.forum_id = 19 or t.forum_id = 35 or t.forum_id = 42 or t.forum_id = 23 or t.forum_id = 36 or t.forum_id = 13 or t.forum_id = 14 or t.forum_id = 54 or t.forum_id = 46 or t.forum_id = 47 or t.forum_id = 16 or t.forum_id = 51 or t.forum_id = 52 or t.forum_id = 17 or t.forum_id = 53 or t.forum_id = 20 or t.forum_id = 43 or t.forum_id = 44 or t.forum_id = 12 or t.forum_id = 41 or t.forum_id = 56 ORDER BY t.last_post DESC LIMIT ".$ipb_limit, $ipb_db_connection);
} else if ( $member['group_id'] == 7 ) { //supermods
$ipb_query = mysql_query("SELECT DISTINCT t.tid, t.title, t.last_poster_name, t.last_poster_id, t.starter_id, t.starter_name, t.forum_id, f.read_perms FROM ".$ipb_table_prefix."topics t INNER JOIN ".$ipb_table_prefix."forums f ON t.forum_id = f.id where t.forum_id = 1 or t.forum_id = 2 or t.forum_id = 30 or t.forum_id = 58 or t.forum_id = 45 or t.forum_id = 3 or t.forum_id = 10 or t.forum_id = 33 or t.forum_id = 38 or t.forum_id = 50 or t.forum_id = 55 or t.forum_id = 19 or t.forum_id = 35 or t.forum_id = 42 or t.forum_id = 23 or t.forum_id = 36 or t.forum_id = 13 or t.forum_id = 14 or t.forum_id = 54 or t.forum_id = 46 or t.forum_id = 47 or t.forum_id = 16 or t.forum_id = 51 or t.forum_id = 52 or t.forum_id = 17 or t.forum_id = 53 or t.forum_id = 20 or t.forum_id = 43 or t.forum_id = 44 or t.forum_id = 12 or t.forum_id = 41 or t.forum_id = 56 ORDER BY t.last_post DESC LIMIT ".$ipb_limit, $ipb_db_connection);
} else if ( $member['group_id'] == 19 ) { //globalmods
$ipb_query = mysql_query("SELECT DISTINCT t.tid, t.title, t.last_poster_name, t.last_poster_id, t.starter_id, t.starter_name, t.forum_id, f.read_perms FROM ".$ipb_table_prefix."topics t INNER JOIN ".$ipb_table_prefix."forums f ON t.forum_id = f.id where t.forum_id = 1 or t.forum_id = 2 or t.forum_id = 30 or t.forum_id = 58 or t.forum_id = 45 or t.forum_id = 3 or t.forum_id = 10 or t.forum_id = 33 or t.forum_id = 38 or t.forum_id = 50 or t.forum_id = 55 or t.forum_id = 19 or t.forum_id = 35 or t.forum_id = 42 or t.forum_id = 23 or t.forum_id = 36 or t.forum_id = 13 or t.forum_id = 14 or t.forum_id = 54 or t.forum_id = 46 or t.forum_id = 47 or t.forum_id = 16 or t.forum_id = 51 or t.forum_id = 52 or t.forum_id = 17 or t.forum_id = 53 or t.forum_id = 20 or t.forum_id = 43 or t.forum_id = 44 or t.forum_id = 12 or t.forum_id = 41 ORDER BY t.last_post DESC LIMIT ".$ipb_limit, $ipb_db_connection);
} else if ( $member['group_id'] == 6 ) { //mods
$ipb_query = mysql_query("SELECT DISTINCT t.tid, t.title, t.last_poster_name, t.last_poster_id, t.starter_id, t.starter_name, t.forum_id, f.read_perms FROM ".$ipb_table_prefix."topics t INNER JOIN ".$ipb_table_prefix."forums f ON t.forum_id = f.id where t.forum_id = 1 or t.forum_id = 2 or t.forum_id = 30 or t.forum_id = 58 or t.forum_id = 45 or t.forum_id = 3 or t.forum_id = 10 or t.forum_id = 33 or t.forum_id = 38 or t.forum_id = 50 or t.forum_id = 55 or t.forum_id = 19 or t.forum_id = 35 or t.forum_id = 42 or t.forum_id = 23 or t.forum_id = 36 or t.forum_id = 13 or t.forum_id = 14 or t.forum_id = 54 or t.forum_id = 46 or t.forum_id = 47 or t.forum_id = 16 or t.forum_id = 51 or t.forum_id = 52 or t.forum_id = 17 or t.forum_id = 53 or t.forum_id = 20 or t.forum_id = 43 or t.forum_id = 44 or t.forum_id = 12 or t.forum_id = 41 ORDER BY t.last_post DESC LIMIT ".$ipb_limit, $ipb_db_connection);
} else if ( $member['group_id'] == 14 ) { //News Posters
$ipb_query = mysql_query("SELECT DISTINCT t.tid, t.title, t.last_poster_name, t.last_poster_id, t.starter_id, t.starter_name, t.forum_id, f.read_perms FROM ".$ipb_table_prefix."topics t INNER JOIN ".$ipb_table_prefix."forums f ON t.forum_id = f.id where t.forum_id = 1 or t.forum_id = 2 or t.forum_id = 30 or t.forum_id = 58 or t.forum_id = 45 or t.forum_id = 3 or t.forum_id = 10 or t.forum_id = 33 or t.forum_id = 38 or t.forum_id = 50 or t.forum_id = 55 or t.forum_id = 19 or t.forum_id = 35 or t.forum_id = 42 or t.forum_id = 23 or t.forum_id = 36 or t.forum_id = 13 or t.forum_id = 14 or t.forum_id = 54 or t.forum_id = 46 or t.forum_id = 47 or t.forum_id = 16 or t.forum_id = 51 or t.forum_id = 52 or t.forum_id = 17 or t.forum_id = 53 or t.forum_id = 20 or t.forum_id = 43 or t.forum_id = 44 or t.forum_id = 12 or t.forum_id = 41 ORDER BY t.last_post DESC LIMIT ".$ipb_limit, $ipb_db_connection);
} else if ( $member['group_id'] == 18 ) { //fund donors
$ipb_query = mysql_query("SELECT DISTINCT t.tid, t.title, t.last_poster_name, t.last_poster_id, t.starter_id, t.starter_name, t.forum_id, f.read_perms FROM ".$ipb_table_prefix."topics t INNER JOIN ".$ipb_table_prefix."forums f ON t.forum_id = f.id where t.forum_id = 1 or t.forum_id = 2 or t.forum_id = 30 or t.forum_id = 58 or t.forum_id = 45 or t.forum_id = 3 or t.forum_id = 10 or t.forum_id = 33 or t.forum_id = 38 or t.forum_id = 50 or t.forum_id = 55 or t.forum_id = 19 or t.forum_id = 35 or t.forum_id = 42 or t.forum_id = 23 or t.forum_id = 36 or t.forum_id = 13 or t.forum_id = 14 or t.forum_id = 54 or t.forum_id = 46 or t.forum_id = 47 or t.forum_id = 16 or t.forum_id = 51 or t.forum_id = 52 or t.forum_id = 17 or t.forum_id = 53 or t.forum_id = 20 or t.forum_id = 43 or t.forum_id = 44 ORDER BY t.last_post DESC LIMIT ".$ipb_limit, $ipb_db_connection);
} else if ( $member['group_id'] == 12 ) { //Members..
$ipb_query = mysql_query("SELECT DISTINCT t.tid, t.title, t.last_poster_name, t.last_poster_id, t.starter_id, t.starter_name, t.forum_id, f.read_perms FROM ".$ipb_table_prefix."topics t INNER JOIN ".$ipb_table_prefix."forums f ON t.forum_id = f.id where t.forum_id = 1 or t.forum_id = 2 or t.forum_id = 30 or t.forum_id = 58 or t.forum_id = 45 or t.forum_id = 3 or t.forum_id = 10 or t.forum_id = 33 or t.forum_id = 38 or t.forum_id = 50 or t.forum_id = 55 or t.forum_id = 19 or t.forum_id = 35 or t.forum_id = 42 or t.forum_id = 23 or t.forum_id = 36 or t.forum_id = 13 or t.forum_id = 14 or t.forum_id = 54 or t.forum_id = 46 or t.forum_id = 47 or t.forum_id = 16 or t.forum_id = 51 or t.forum_id = 52 or t.forum_id = 17 or t.forum_id = 53 or t.forum_id = 20 or t.forum_id = 43 ORDER BY t.last_post DESC LIMIT ".$ipb_limit, $ipb_db_connection);
} else if ( $member['group_id'] == 10 ) { //Members.
$ipb_query = mysql_query("SELECT DISTINCT t.tid, t.title, t.last_poster_name, t.last_poster_id, t.starter_id, t.starter_name, t.forum_id, f.read_perms FROM ".$ipb_table_prefix."topics t INNER JOIN ".$ipb_table_prefix."forums f ON t.forum_id = f.id where t.forum_id = 1 or t.forum_id = 2 or t.forum_id = 30 or t.forum_id = 58 or t.forum_id = 45 or t.forum_id = 3 or t.forum_id = 10 or t.forum_id = 33 or t.forum_id = 38 or t.forum_id = 50 or t.forum_id = 55 or t.forum_id = 19 or t.forum_id = 35 or t.forum_id = 42 or t.forum_id = 23 or t.forum_id = 36 or t.forum_id = 13 or t.forum_id = 14 or t.forum_id = 54 or t.forum_id = 46 or t.forum_id = 47 or t.forum_id = 16 or t.forum_id = 51 or t.forum_id = 52 or t.forum_id = 17 or t.forum_id = 53 ORDER BY t.last_post DESC LIMIT ".$ipb_limit, $ipb_db_connection);
} else { //Members
$ipb_query = mysql_query("SELECT DISTINCT t.tid, t.title, t.last_poster_name, t.last_poster_id, t.starter_id, t.starter_name, t.forum_id, f.read_perms FROM ".$ipb_table_prefix."topics t INNER JOIN ".$ipb_table_prefix."forums f ON t.forum_id = f.id where t.forum_id = 1 or t.forum_id = 2 or t.forum_id = 30 or t.forum_id = 58 or t.forum_id = 45 or t.forum_id = 3 or t.forum_id = 10 or t.forum_id = 33 or t.forum_id = 38 or t.forum_id = 50 or t.forum_id = 55 or t.forum_id = 19 or t.forum_id = 35 or t.forum_id = 42 or t.forum_id = 23 or t.forum_id = 36 or t.forum_id = 13 or t.forum_id = 14 or t.forum_id = 54 or t.forum_id = 46 or t.forum_id = 47 ORDER BY t.last_post DESC LIMIT ".$ipb_limit, $ipb_db_connection); }