Jump to content

Recommended Posts

Hi all

 

Can someone help me sort this one out? My current code is

$forums=@mysql_query("Select 
T.replies AS TOPICREPLIES,
T.replytime AS REPLYTIME,
T.replyusername AS REPLYUSERNAME,
T.id AS TOPICID
,T.subject AS TOPICSUBJECT,
T.username AS TOPICUSERNAME,
F.id AS FORUMID,
F.subject AS FORUMSUBJECT,
T.timeposted AS TOPICTIMEPOSTED 
From (forumforums F LEFT OUTER JOIN forumtopics T ON F.id=T.forumid) Order By T.replytime Desc");

Now I want only the last topic reply (in forumtopics) for each forum (in forumforums). But it doesn't limit to just the last post made in each forum, it will show more than just the last post. Any ideas? I can't get GROUP to work?

 

Thanks for your help!

Something just looks terribly wrong about your code...Maybe its me being an amateur.  :'(

 

 

From what it sounds like, this would help:

 

$querytopic = "SELECT * FROM topics ORDER BY time DESC" or die();

 

In this case you would need your topics to have a time by last they were posted, so if someone posts, bring the time to time(). That will give you all your topics by DESC. Now just select the first row and bingo! Your done. I think.

sorry, that will only show the topics. this code should show the forums as well as the last post in each topic, in each forum.

 

Topic*  :)

 

What that code does there if you limit it to 1 will display the most recent posted topic. If you want the post, that shouldn't be too hard to modify. Do the same as topic, except switch it with post. The only issue I could think that will occure is if two topics/posts have the same amount of time...Then I'm not sure how it decides.

sorry if you misunderstood. here is the 2 tables:

 

table1 - forumforums

id

subject

 

table2 - forumtopics

id

forumid

username

timeposted

msg

subject

replies

replyusername

replytime

 

so what i need is each forum in forumforums shown in order of last post done in any topic that's part of the forum. The forumforums.id will equal forumtopics.forumid as shown in my code. But for some reason I cannot group table1 or table2 properly so that it shows each forumforums.id once only

Then just change the GROUP to use the forum id on the forum table and use an IF_NULL to populate the topic fields [edit: and use a LEFT JOIN].

 

e.g.:

 

SELECT [Fields ... ], IFNULL(t.subject, 'No topics found')

FROM forumforums f

LEFT JOIN forumtopics t ON (f.id = t.forumid)

GROUP BY f.id

ORDER BY t.replytime DESC

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.