Jump to content

Recommended Posts

I am trying to create my own forum system and am trying to replicate the way phpBB sorts posts with recent replies to the top of the list. I have all posts and replies in one table and am trying not to add a last_reply field to the table.

 

here goes,

 

I have one table lets call it T1

 

for this purpose we can say T1 has 3 fields:

 

message_ID - Auto_Incremented Primary Key (each one is unique)

 

parent_ID - INT (where parent_ID = 0 if not a reply and parent_id=message_id of post relpied to)

 

lastdate - TIMESTAMP (date posted)

 

Here is what I want to do with this:

First I want to select all messages with such that parent_id=0

then I want this sorted in the order of which has the most recent reply so it would have to sort through the replies of each and pick out the most recent date and sort the list of parent_id=0.

 

this just has my head spinning

 

I am using mysql 3.22

Is there a way for me to do this in just sql? if not php? am I just going to have to do something different?

 

I would be soooo grateful for any help!

Link to comment
https://forums.phpfreaks.com/topic/1215-help-please/
Share on other sites

maybe I made it confusing.

 

lastdate is supposed to called postdate actually. There is no lastdate column.

 

each row contains a message_id a parent_id and postdate

 

first I want to select all with parent_id = 0 that is no problem

 

to get each message which is not a reply i do this

 

SELECT* FROM T1 WHERE parent_id=0 ORDER BY postdate)

 

to get the replies for that message I do this

SELECT * FROM T1 WHERE parent_id=\'id of message getting replies of\' ORDER BY postdate

 

Now when I display the messages with that first query I want those results to be sorted by the dates of each in the second query

 

get it?[/code]

Link to comment
https://forums.phpfreaks.com/topic/1215-help-please/#findComment-4070
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.