Jump to content

pull up Last Post with topic title name


dadamssg

Recommended Posts

Developing a forum. i have a table named Topics with the topic_name, content, create_date, created_by, and topic_id. And then i have a table name Responses with content, create_date, created_by, topic_id, and response_id. I want to list out the Topic names and then have the when the last response and who it it was by next to it, exactly like this forum. I am clueless how i would write the query to do that though.

 

i need to combine this to pull up all topics

$query = "SELECT * FROM Topics WHERE 1 ORDER BY create_date DESC";

 

with another query to pull up the last post date and user.

 

anybody know how to do this?

 

Link to comment
Share on other sites

Just JOIN the tables (and don't use the asterisk - in joint tables it will lead to problems anyway)

What is "WHERE 1" good for btw?

 

SELECT Top.topic_name, Res.create_date, Res.created_by FROM Topics AS Top JOIN Responses as Res ON Top.topic_id = Res.topic_id ORDER BY create_date DESC LIMIT 1;

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.