Jump to content

Numbering problem


fazzfarrell

Recommended Posts

try

[code]SELECT ID, DATE, USERNAME, TITLE, MESSAGE
FROM Message
UNION ALL
SELECT ReplyID, DATE, USERNAME, TITLE, MESSAGE
FROM MessageR
ORDER BY Message.DATE DESC, MessageR.Date DESC[/code]

One other thing, Using UNION is probably not your best bet here. If someone answers a message that is really old it will not show correctly. I am guessing that you want to have the messages show, and under each message show replies. If that is the case you should link the 2 tables with a common field.

Message table can stay the same but you should add a field in MessageR called MessageID. This should contain the ID from the message table that way when you query it will link everything together.
[code]SELECT Message.DATE AS m_date, Message.USERNAME AS m_user, Message.TITLE AS m_title, Message.MESSAGE AS m_message,
MessageR.DATE AS r_date, MessageR.TITLE AS r_title, MessageR.MESSAGE AS r_message
FROM Message
LEFT JOIN MessageR ON Message.ID = MessageR.MessageID
ORDER BY Message.DATE DESC, MessageR.Date DESC[/code]

Now the tables are linked.

Ray
Link to comment
https://forums.phpfreaks.com/topic/36319-numbering-problem/#findComment-172723
Share on other sites

I have set it up like this as i already had a field that held the ID number from the Message table.

[code]
SELECT Message.DATE AS m_date, Message.USERNAME AS m_user, Message.TITLE AS m_title, Message.MESSAGE AS m_message,
MessageR.DATE AS r_date, MessageR.TITLE AS r_title, MessageR.MESSAGE AS r_message
FROM Message
LEFT JOIN MessageR ON Message.ID = MessageR.MessageID
ORDER BY Message.DATE DESC, MessageR.Date DESC
[/code]

Problem is now that it is not showing all the mesages from both tables, it just repeats any entry with a reply twice?
Link to comment
https://forums.phpfreaks.com/topic/36319-numbering-problem/#findComment-172828
Share on other sites

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.