Hello,
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("
SELECT f.*
FROM ".TABLE_PREFIX."forums f
WHERE f.active != 0 AND f.fid IN('1','4','5')
ORDER BY pid, disporder
");
Where:
- 1 - parent / category.
- 4 - Forum first / child.
- 5 - Forum second / child 2.
You think
WHERE [...] f.pid IN('1','OTHER_ID_CATEGORY')
?
If I use this code, it displays my forums, but not 'in the form subforum'.
Each separately.
Template:
<div class="col">
<strong><a href="{$forum_url}">{$forum['name']}</a></strong><br />{$subforums}
</div>
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']]
else
// 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: http://community.mybb.com/thread-169977-post-1155390.html#pid1155390
$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').'";');
else
{
// w przeciwnym wypadku mamy forum "rodzica" - zapisujesz jego "dzieci" do prostszej zmiennej
$subfora = '';
if(isset($subforums[$forum['fid']]))
$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: