Code:
SELECT c.id AS catid, f.id AS forumid, f.name AS forumname, f.description, MAX(r.datum) AS last_reply_date, t.id AS last_thread_id, t.title AS last_thread_title, u.username AS last_reply_user FROM forum_cats AS c INNER JOIN forum_forums AS f ON f.cat_id = c.id LEFT JOIN forum_replys AS r ON r.forum_id = f.id LEFT JOIN forum_threads AS t ON t.id = r.thread_id LEFT JOIN users AS u ON u.id = r.user_id GROUP BY f.id ORDER BY c.id ASC , f.id ASC;
Das last_reply_date ist das richtige.
Die last_thread_id die falsche.
Der last_thread_title ebenfalls der falsche.
Demgemäß dürfte das Problem beim zweiten LEFT JOIN liegen.
Ich denke mal er wählt nicht den Datensatz aus, den ich mit MAX(r.datum) "anspreche".
Es sollen alle "foren" und die details zu den letzten (vom datum her) Beiträgen darin ausgelesen werden.
tabellenstruktur:
Code:
-- -- Table structure for table `forum_cats` -- CREATE TABLE forum_cats ( id int(10) unsigned NOT NULL auto_increment, name varchar(100) NOT NULL default '', PRIMARY KEY (id), KEY name (name) ) TYPE=MyISAM; -- -------------------------------------------------------- -- -- Table structure for table `forum_forums` -- CREATE TABLE forum_forums ( id int(10) unsigned NOT NULL auto_increment, cat_id int(10) NOT NULL default '0', name varchar(100) NOT NULL default '', private tinyint(1) NOT NULL default '0', description varchar(250) NOT NULL default '', PRIMARY KEY (id), KEY cat_id (cat_id,name) ) TYPE=MyISAM; -- -------------------------------------------------------- -- -- Table structure for table `forum_replys` -- CREATE TABLE forum_replys ( id int(10) unsigned NOT NULL auto_increment, thread_id int(10) NOT NULL default '0', forum_id int(10) NOT NULL default '0', user_id int(10) NOT NULL default '0', datum int(20) NOT NULL default '0', title varchar(100) NOT NULL default '', text text NOT NULL, bbcode tinyint(1) NOT NULL default '0', PRIMARY KEY (id), KEY thread_id (thread_id,forum_id,user_id), FULLTEXT KEY text (text) ) TYPE=MyISAM; -- -------------------------------------------------------- -- -- Table structure for table `forum_threads` -- CREATE TABLE forum_threads ( id int(10) unsigned NOT NULL auto_increment, forum_id int(10) NOT NULL default '0', user_id int(10) NOT NULL default '0', title varchar(100) NOT NULL default '', closed tinyint(1) NOT NULL default '0', sticky tinyint(1) NOT NULL default '0', PRIMARY KEY (id), KEY forum_id (forum_id,user_id) ) TYPE=MyISAM; -- -------------------------------------------------------- -- -- Table structure for table `users` -- CREATE TABLE users ( id int(10) unsigned NOT NULL auto_increment, username varchar(50) NOT NULL default '', ........ ) TYPE=MyISAM;
Kommentar