Jump to content

Forums


Daney11

Recommended Posts

Hey guys,

 

This is going to be a long one.

 

I have created my own simple forum for my website. http://one.team-who.co.uk/forums.php

 

I have 3 tables for the forums.

 

forums

-forum_id

-forum_name

-forum_type

-forum_heading

 

forum_topics

-forum_topic_id

-forum_topic_forumid

-forum_topic_date

-forum_topic_memberid

-forum_topic_name

-forum_topic_body

 

forum_posts

-forum_post_id

-forum_post_forumid

-forum_post_date

-forum_post_topicid

-forum_post_memberid

-forum_post_body

 

Now if you see my forums, http://one.team-who.co.uk/forum.php?forum_id=1, i need to code it so that the Last Post date is the highest, and currently it is now. For example

 

Last Post - would be wrong

2008-03-17 20:00:00

2008-03-17 21:00:00

Last Post - would be correct

2008-03-17 21:00:00

2008-03-17 20:00:00

 

So obviously i need to JOIN the tables but im not really sure how. At the moment i have

 

$forumTopicQuery = "SELECT * FROM forum_topics WHERE  forum_topic_forumid = $forum_id AND forum_topic_id = $forum_topic_id LIMIT 1";
$forumTopicresult = mysql_query($forumTopicQuery, $connect) or die(mysql_error());

 

AND

 

$forumPostsQuery = "SELECT * FROM forum_posts WHERE  forum_post_topicid = $forum_topic_id ORDER BY forum_post_date ASC";
$forumPostsresult = mysql_query($forumPostsQuery, $connect) or die(mysql_error());

 

So now the forum_posts ORDER by date DESC. But i need it so the LAST POST entered in ANY topic is at the top of my forum list.

 

I hope this makes sense to people.

 

Any help would be great

 

Thanks a lot

Link to comment
Share on other sites

But I think your looking for something like this.

$forumTopicQuery = "SELECT * FROM forum_topics, forum_posts WHERE forum_topics.forum_topic_id = forum_posts.forum_post_topicid and forum_topics.forum_topic_forumid = $forum_id AND forum_topics.forum_topic_id = $forum_topic_id ORDER BY forum_posts.forum_post_date ASC LIMIT 1";

 

Link to comment
Share on other sites

I get

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY forum_posts.forum_post_date DESC' at line 1

 

$ForumTopicQuery = "SELECT * FROM forum_topics, forum_posts WHERE forum_topics.forum_topic_teamid = $team_url AND forum_topics.forum_topic_id = forum_posts.forum_post_topicid AND forum_topics.forum_topic_forumid = $forum_id AND forum_topics.forum_topic_id = $forum_topic_id ORDER BY forum_posts.forum_post_date DESC";

Link to comment
Share on other sites

forum_topics

-forum_topic_id

-forum_topic_forumid

-forum_topic_date

-forum_topic_memberid

-forum_topic_name

-forum_topic_body

-forum_topic_lastpost

 

Then what you'd do is UPDATE forum_topics SET forum_topic_lastpost = $date(ofnewpost)

 

Along the right lines?

Link to comment
Share on other sites

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.