TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   MySQL & Databases (http://www.talkphp.com/mysql-databases/)
-   -   Selecting Latest Forum Post Threads (http://www.talkphp.com/mysql-databases/2237-selecting-latest-forum-post-threads.html)

aristoworks 02-12-2008 08:05 PM

Selecting Latest Forum Post Threads
 
I've made a simple user forum on a site. More along the lines of "threaded comments".

On my front page I'd like to show the top 5 latest commented threads.

IE - 5 Threads that received the latest comments.

Code:

CREATE TABLE `forumPost` (
  `id` int(5) NOT NULL auto_increment,
  `thread` int(5) NOT NULL default '0',
  `text` text NOT NULL,
  `user` int(5) NOT NULL default '0',
  `date` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

Code:

CREATE TABLE `forumThread` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

I'm having trouble with the query logic.

Basically something like:

Code:

SELECT * FROM forumPost GROUP BY(DISTINCT(thread)) ORDER BY date DESC
obviously this doesn't work. Any ideas on how to do this without going the easy PHP route?

Thanks
jw

xenon 02-12-2008 10:05 PM

Perhaps this is what you want to achieve:

Code:

SELECT DISTINCT(thread) FROM forumPost [...]


All times are GMT. The time now is 07:43 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0