@RobiNN - Well, I'm focusing only on issues related to core.
Anyway, did you tried LEFT JOIN and nested loops?
$result = dbquery("SELECT tp.topic_id, tp.topic_title, tp.topic_parentid FROM ".DB_GRIMS_BLOG_TOPICS." tp
LEFT JOIN ".DB_GRIMS_BLOG_POSTS." ps ON tp.topic_id=ps.post_id WHERE tp.topic_parentid='0'$result = dbquery("SELECT tp.topic_id, tp.topic_title, tp.topic_parentid FROM ".DB_GRIMS_BLOG_TOPICS." tp
LEFT JOIN ".DB_GRIMS_BLOG_POSTS." ps ON tp.topic_id=ps.post_id WHERE tp.topic_parentid=tp.topic_id");<?php
echo "<div class='col-sm-12'>\n";
echo "<table width='100%' border='0'><tr><td><span class='hdspan2'><b>".$locale['gb_810']."</b></span></td></tr></table>\n";
echo "<table align='center' width='80%' border='0'>\n";
$result = dbquery("SELECT * FROM ".DB_GRIMS_BLOG_TOPICS."");
while($data = dbarray($result)) {
$id = $data['topic_id'];
$title = $data['topic_title'];
$sub = $data['topic_parent'];
$result1 = dbquery("SELECT * FROM ".DB_GRIMS_BLOG_POST." WHERE topic_id='$id'");
$num_rows = dbrows($result1);
if($sub>0) {
echo "<tr><td width='15'></td><td>»» <a class='lnk-side' href='".BASEDIR."grims_blog/topics_page.php?topic_id=".$id."'>$title</a><span style='font-size:11px;color:white;'> [$num_rows posts]</span></td></tr>\n";
} else {
echo "<tr><td colspan='2'><a class='lnk-side' href='".BASEDIR."grims_blog/topics_page.php?topic_id=".$id."'>$title</a><span style='font-size:11px;color:white;'> [$num_rows posts]</span></td></tr>\n";
}
}
echo "</table><p></div>\n";
?>
$result = dbquery("SELECT child.id, child.title as subtitle, parent.title as parenttitle FROM test AS parent JOIN test AS child ON (child.parent = parent.id)");
while ($data = dbarray($result)) {
echo $data['parenttitle'];
echo "---".$data['subtitle']."<br>";
}
@douwe_yntema - Did some googling and tests with the following code:
Code Download source
$result = dbquery("SELECT child.id, child.title as subtitle, parent.title as parenttitle FROM test AS parent JOIN test AS child ON (child.parent = parent.id)");
while ($data = dbarray($result)) {
echo $data['parenttitle'];
echo "---".$data['subtitle']."<br>";
}
$result = dbquery("SELECT tp.topic_id, tp.topic_title, tp.topic_parent, sp.topic_title, sp.topic_parent FROM ".DB_GRIMS_BLOG_TOPICS." tp
JOIN ".DB_GRIMS_BLOG_TOPICS." sp.topic_id, sp.topic_title, sp.topic_parent WHERE tp.topic_id = sp.topic_parent");@Grimloch - If you look at Post#6 there is an image of the db table.
@Grimloch - Tell me if this will work for the join. Even if it will I have no idea how to gather and display the data below the query. I'm grabbing at straws here folks.
Code Download source$result = dbquery("SELECT tp.topic_id, tp.topic_title, tp.topic_parent, sp.topic_title, sp.topic_parent FROM ".DB_GRIMS_BLOG_TOPICS." tp
JOIN ".DB_GRIMS_BLOG_TOPICS." sp.topic_id, sp.topic_title, sp.topic_parent WHERE tp.topic_id = sp.topic_parent");
echo "<table align='center' width='80%' border='0'><tr><td>\n";
$result = dbquery("SELECT child.topic_id, child.topic_title as subtitle, parent.topic_title as parenttitle FROM ".DB_GRIMS_BLOG_TOPICS." AS parent
JOIN ".DB_GRIMS_BLOG_TOPICS." AS child ON (child.topic_parent = parent.topic_id");
while ($data = dbarray($result)) {
echo $data['parenttitle'];
echo "---".$data['subtitle']."<br>";
}
echo "</td></tr></table><p></div>\n";[17-May-2021 07:42:05 America/Chicago] PHP Fatal error: Uncaught Error: Call to a member function setFetchMode() on null in /home/whisperw/blog.whisperwillow.net/includes/db_handlers/pdo_functions_include.php:120
Stack trace:
#0 /home/whisperw/blog.whisperwillow.net/grims_blog/include/latest_topics.php(7): dbarray(NULL)
#1 /home/whisperw/blog.whisperwillow.net/grims_blog/include/modules.php(6): include('/home/whisperw/...')
#2 /home/whisperw/blog.whisperwillow.net/grims_blog/index.php(43): include('/home/whisperw/...')
#3 {main}
thrown in /home/whisperw/blog.whisperwillow.net/includes/db_handlers/pdo_functions_include.php on line 120
[17-May-2021 07:42:07 America/Chicago] PHP Fatal error: Uncaught Error: Call to a member function setFetchMode() on null in /home/whisperw/blog.whisperwillow.net/includes/db_handlers/pdo_functions_include.php:120
Stack trace:
#0 /home/whisperw/blog.whisperwillow.net/grims_blog/include/latest_topics.php(7): dbarray(NULL)
#1 /home/whisperw/blog.whisperwillow.net/grims_blog/include/modules.php(6): include('/home/whisperw/...')
#2 /home/whisperw/blog.whisperwillow.net/grims_blog/index.php(43): include('/home/whisperw/...')
#3 {main}
thrown in /home/whisperw/blog.whisperwillow.net/includes/db_handlers/pdo_functions_include.php on line 120
[18-May-2021 07:25:37 America/Chicago] PHP Fatal error: Uncaught Error: Call to a member function setFetchMode() on null in /home/whisperw/blog.whisperwillow.net/includes/db_handlers/pdo_functions_include.php:120
Stack trace:
#0 /home/whisperw/blog.whisperwillow.net/grims_blog/include/latest_topics.php(8): dbarray(NULL)
#1 /home/whisperw/blog.whisperwillow.net/grims_blog/include/modules.php(6): include('/home/whisperw/...')
#2 /home/whisperw/blog.whisperwillow.net/grims_blog/index.php(43): include('/home/whisperw/...')
#3 {main}
thrown in /home/whisperw/blog.whisperwillow.net/includes/db_handlers/pdo_functions_include.php on line 120$result = dbquery("SELECT child.topic_id, child.topic_title as subtitle, parent.topic_title as parenttitle FROM ".DB_GRIMS_BLOG_TOPICS." AS parent
JOIN ".DB_GRIMS_BLOG_TOPICS." AS child ON (child.topic_parent = parent.topic_id)");
while ($data = dbarray($result)) {
$id = $data['parent(topic_id)'];
$maintitle = $data['parenttitle'];
$subtitle = $data['subtitle'];
if ($maintitle) {
echo "<tr><td colspan='2'><a class='lnk-side' href='".BASEDIR."grims_blog/topics_page.php?topic_id=".$id."'>$maintitle</a></td></tr>\n";
}
if ($subtitle) {
echo "<tr><td width='15'></td><td>» <a class='lnk-side' href='".BASEDIR."grims_blog/topics_page.php?topic_id=".$id."'>$subtitle</td></tr>\n";
}
}@douwe_yntema - Because there is always a maintitle and a subtitle, both links are displayed. That's why you have the maintitles twice.
@Grimloch -@douwe_yntema - Because there is always a maintitle and a subtitle, both links are displayed. That's why you have the maintitles twice.
You are not understanding me; I DO NOT want it that way. I want main title with sub-titles underneath each main title in the proper sequence. Main titles AND sub-titles can have their own distinct posts. If I forget all this and use the added 'topic_order' field that I manually added to the table I can make everything display properly with post counts AND the correct topic_id's but it's a cheat and I can't do it that way. Because the 'topic_order' will change everytime a sub-topic is added or deleted which would require manually changing that field every time.
Anyway I think your suggestion will work I just have to figure out the display part but I need a 'distinct topic_id'; so far everything I've tried won't work with your code.