Jump to content

[SOLVED] Need help with a somewhat complex query.


NeoMarine

Recommended Posts

Ok so here is the structure of my table:

ID - OwnersID - TheMessage - DateTimeAdded - UsersID - RepliedToStartID - RepliedToLevel

 

What I'm trying to accomplish:

I display a series of messages on the page, and I allow users to "reply" to a particular message. When someone replies to that message, I need it to be displayed "underneath" the message it was a reply to.

 

How I store my data:

I use the column RepliedToStartID as the "ID" of the row that the message is owned by, at the very base level. The RepliedToLevel tells me the "level" deep the message is at. So, if john (whos ID is 100) wrote a message and sarah replied to the message later on (whos ID is 105), on screen it should show johns message, followed by sarahs message - and sarahs RepliedToStartID = johns ID (100), and RepliedToLevel = 1.

 

The query:

The query therefore needs to "ORDER" the messages "BY" the DateAdded, and then if a previous rows ID = the next rows RepliedToStartID, that row should be placed after the previous row.

 

One idea I had was to use multiple queries, which would be rather simple - but also taxing on the server - I dont want to slow things down. So, essentially I must create a query that selects the rows by their RepliedToStartID, as well as the DateAdded and RepliedToLevel - but in the ORDER of "Message (100)" and then "Message (105)" -- 105 being the message with RepliedToStartID of 100 and Message 100 being the previous message displayed.

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.