I always seem to become stupid when trying to get a LEFT JOIN statement working correctly.
Here's the scenario. I am trying to have (2) seperate MYSQL queries for the occasion when the forum page being displayed only has a select number of topics (for the $forum_id in question).
This is to be able to supply the pagination script with the correct number of pages, etc.
I want to retrieve all matching records on [forums] where they match records found in [groups]. Variables at hand; $forum_id and $g_id (group_id). If group_id is empty then the variable was not supplied in the string and is probably the default value of "0" (not that this is helpful).
if($g_id=='') {
$forums = mysql_query("SELECT forum_name, forum_desc, forum_readaccess, forum_posts, forum_topics, forum_writeaccess FROM $pntablemod[forums] WHERE forum_id = $forum_id");
} else {
$forums = mysql_query("SELECT forum_name, forum_desc, forum_readaccess, forum_posts, forum_topics, forum_writeaccess FROM $pntablemod[forums] LEFT JOIN $pntablemod[groups] ON forum_id = parent_forum WHERE forum_id = $forum_id");
}
The upper query is the original query to return all matching results for $forum_id = forum_id.
Any help would be great. I have tried numerous combinations, INNER JOINS, RIGHT JOINS, and nadda! 🙁
I can provide more code if needed. Here is the page it's working/not working on. Click "Guntrucks" for where the upper query is called.
http://www.armorama.com/modules.php?op=modload&name=postbox&file=index&req=viewforum&forum_id=5&page=1
Thanks,
Jim