Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 02-09-2005, 03:55 PM   PM User | #1
andyede
Regular Coder

 
Join Date: Sep 2004
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
andyede is an unknown quantity at this point
Distinct records ordered by date

I have the basis of a forum similar in workings to this one. I am using perl with MySQL the problem i have is a simple SQL one.

I have a table storing all post data including fields.
forumID,
threadID,
postID,
postTitle,
datePosted,
timePosted

I want to list the threads in the order of last posted/replied to. So similar to this you click on the forum you want view and you get a list of the threads in that forum with the most recently active at the top. I don't mind how much data i can get for each thread, i can handle just getting the threadID and then i can loop back through it again and get the specific data for that thread (infact this would be preferable as it would give me more control although would work the server alittle harder).

the closest SQL i have to working is

Code:
SELECT DISTINCT threadID FROM postdata WHERE forumID='$fid' ORDER BY dataPosted, timePosted DESC;
but the order seems not to change

SQL is not my best subject, any ideas welcome
andyede is offline   Reply With Quote
Old 02-10-2005, 06:32 AM   PM User | #2
Kiwi
Regular Coder

 
Join Date: Oct 2002
Posts: 379
Thanks: 0
Thanked 0 Times in 0 Posts
Kiwi is an unknown quantity at this point
Does this work in mySQL?
PHP Code:
SELECT a.threadID MAX(a.dataPosted) as PostDate
FROM postdata a
WHERE b
.forumID='$fid'
GROUP BY a.threadID
ORDER BY PostDate

__________________
Strategy Conscious

Last edited by Kiwi; 02-10-2005 at 06:49 AM..
Kiwi is offline   Reply With Quote
Old 02-17-2005, 12:07 PM   PM User | #3
andyede
Regular Coder

 
Join Date: Sep 2004
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
andyede is an unknown quantity at this point
no that just brings up an error. i've given up trying to so it in SQL. i just get an ordered list of thread IDs and remove the duplicate items in perl. i think each thread has to make about 5 database queries to get all the information now
andyede is offline   Reply With Quote
Old 02-17-2005, 03:40 PM   PM User | #4
Julian Turner
New to the CF scene

 
Join Date: Feb 2005
Location: Derby, UK
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Julian Turner is an unknown quantity at this point
Quote:

SELECT a.threadID MAX(a.dataPosted) as PostDate
FROM postdata a
WHERE b.forumID='$fid'
GROUP BY a.threadID
ORDER BY PostDate;
Should that not be

WHERE a.forumID='$fid'
Julian Turner is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:35 PM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.