MyBB Community Forums

Full Version: Forums and Subforums on the subpage.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I create some a project, and I must download some forums, okay, I used query:

$query = $db->query("
    SELECT f.*
    FROM ".TABLE_PREFIX."forums f
    WHERE f.fid IN('4')
    ORDER BY pid, disporder

Now I need segregate to this sub forums.

Any suggestions?

Greet, Snake_.
Okay, now I've found That must been parent - we query this download.
How now download 'child', 'sub-forums' from the parent?
if only the closest children, you can make use of the pid (parent ID) column in the mybb_forums table
Well, how do you see? My current query:
$query = $db->query("
	FROM ".TABLE_PREFIX."forums f
	WHERE != 0 AND f.fid IN('1','4','5')
	ORDER BY pid, disporder
  • 1 - parent / category.
  • 4 - Forum first / child.
  • 5 - Forum second / child 2.
You think
If I use this code, it displays my forums, but not 'in the form subforum'.
Each separately.
<div class="col">
<strong><a href="{$forum_url}">{$forum['name']}</a></strong><br />{$subforums}
[Image: 553e3c3a5e103.png]
MyForum & MyForum - parents.
Test & Subforum - Subforum/child parents.
There are many ways to separate them. For example, run this query (which could be changed to simple_select() btw):
$query = $db->query("
    SELECT *
    FROM {$db->table_prefix}forums
    WHERE active != 0 AND fid IN(1,4,5) OR pid IN(1,4,5)
    ORDER BY pid, disporder
Then in the while loop, in which $forum is array from the database, do:
if(in_array($forum['pid'], array(1,4,5)))
    // child, so concantenate the subforum to an array with forum-specific indexing, for example $subforums[$forum['pid']]
    // parent, so print forum's template with $subforums[$forum['fid']] representing children. IIRC you'll probably need to reassign it to another simplier variable to avoid "security issue" error.

EDIT: I forgot it may not work properly with that ORDER. You need:
$query = $db->query("
    SELECT *
    FROM {$db->table_prefix}forums
    WHERE active != 0 AND fid IN(1,4,5) OR pid IN(1,4,5)
    ORDER BY FIELD(pid,1,4,5), disporder
or a similar solution with CASE WHEN.
Thanks for the suggestions, bud now I used
$dzialy = $forums[$forum['fid'][$forum['name']]];
No results, this error
Warning [2] Illegal string offset 'My Category' - Line: 28 - File: myfile.php PHP 5.5.21 (Linux)
I didn't use $forum['name'] in my code above anywhere. It's completely redundant, $forum['fid'] is unique so no other index is needed.
Hmm... I still do not understand how concatenate $forum['pid'] (parend) and $forum['fid'] (Child).
Name forums display:
if(in_array($forum['pid'], array(2,3,4,5))) {
		//eval('$subforum .= "'.$templates->get('dld_subforums').'";');
		$subforum .= $forum['name']."<br />";
	} else {
		$nazwa_dzialu .= $forum['name'];
	$dzialy = $nazwa_dzialu . $subforum;
// eval('')...
You're not using the code I posted above. I'll add Polish comments and more lines for better understanding;
// tu oczywiście umieszczasz zapytanie, które musi być posortowane tak jak w EDIT w tym poście:

$subforums = array();

while($forum = $db->fetch_array($query))
    // sprawdzasz czy forum jest "dzieckiem" jednego z "rodziców" 1,4,5 czy jakie tam masz te główne fora
    if(in_array($forum['pid'], array(1,4,5)))
        // przypisujesz szablony "dzieci" do indeksu danego forum "rodzica" - w szablonie używasz np. $forum['name'] i cokolwiek chcesz
        eval('$subforums[$forum["pid"]] .= "'.$templates->get('szablondziecka').'";');
       // w przeciwnym wypadku mamy forum "rodzica" - zapisujesz jego "dzieci" do prostszej zmiennej
       $subfora = '';
           $subfora = $subforums[$forum['fid']];

       // wyświetlasz $subfora, $forum['name'] i co tam chcesz w szablonie "rodzica"
       eval('$listaforow .= "'.$templates->get('szablonrodzica').'";');
I have the impression that there is something wrong with the parents and children.
If I used
if(in_array($forum['pid'], array(4,2))) 
(only forums, not Subforums & category), show only names main forums. In the template "parent" is variable from sub forums, but not display.
4 - first forum,
2 - second forum.

My subforums:
  • 4
    • 5
    • 8
  • 2
    • 3
  • .
Pages: 1 2