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
https://forums.phpfreaks.com/topic/168806-pull-up-last-post-with-topic-title-name/
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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.