fazzfarrell Posted January 29, 2007 Share Posted January 29, 2007 I have my forum working fine, the data comes form two tables Message and MessageR (messageReply table)they are tied together by[code}SELECT Message.ID, Message.`DATE`, Message.USERNAME, Message.EMAIL, Message.MESSAGE, Message.TITLE, Message.BLOCKED, Message.NoReply FROM Message UNION SELECT MessageR.ReplyID, MessageR.`DATE`, MessageR.USERNAME, MessageR.EMAIL, MessageR.MESSAGE, MessageR.TITLE, MessageR.ID, Message.BLOCKEDFROM MessageR, MessageORDER BY Date DESC[code]As they run by date order the newest reply appears at the top of each message, I want the original message not the reply to appear at the top?any ideas?[/code] Link to comment https://forums.phpfreaks.com/topic/36166-order-by/ Share on other sites More sharing options...
trq Posted January 29, 2007 Share Posted January 29, 2007 You need to make another field in your Message table to store the time when a reply is added to the MessageR table.You then order by this. Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-171742 Share on other sites More sharing options...
fazzfarrell Posted January 29, 2007 Author Share Posted January 29, 2007 How can I have two ORDER by? in the same recordset Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-171753 Share on other sites More sharing options...
Snooble Posted January 29, 2007 Share Posted January 29, 2007 calculate both columns and order by that. Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-171759 Share on other sites More sharing options...
fazzfarrell Posted January 29, 2007 Author Share Posted January 29, 2007 Cant seem to get this to work at all! Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-171785 Share on other sites More sharing options...
trq Posted January 29, 2007 Share Posted January 29, 2007 Why would you need to order by both? Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-171798 Share on other sites More sharing options...
fazzfarrell Posted January 29, 2007 Author Share Posted January 29, 2007 Yes,They all need to decend in date order, buy the replys are binding to the origanal post so:I need the original post to be first then the second post to appear below it like this then the next oneAt the moment it apears like this: then the next one then the second post to appear below it like thisI need the original post to be firstSo date order is fine untill its a relpy!? Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-171805 Share on other sites More sharing options...
trq Posted January 29, 2007 Share Posted January 29, 2007 Make two fields, post_date reply_date in your Message table. When an initial post is made put the current time in both, then, when a reply to a post is made update the reply_date to the replies time.Then, simply sort your posts based on the replay_date field.You could actually get away with one date field if you wished. Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-171824 Share on other sites More sharing options...
shoz Posted January 29, 2007 Share Posted January 29, 2007 Post a small example of the the data in the two tables and the output you're looking for. I don't follow why there's a JOIN in the second query of the UNION with no condition on which to join the tables.[quote=fazzfarrell]SELECT MessageR.ReplyID, MessageR.`DATE`, MessageR.USERNAME, MessageR.EMAIL, MessageR.MESSAGE, MessageR.TITLE, MessageR.ID, Message.BLOCKEDFROM MessageR, Message[/quote] Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-171830 Share on other sites More sharing options...
fazzfarrell Posted January 29, 2007 Author Share Posted January 29, 2007 is table atteched[attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-171838 Share on other sites More sharing options...
fazzfarrell Posted January 29, 2007 Author Share Posted January 29, 2007 second table attched[attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-171839 Share on other sites More sharing options...
fazzfarrell Posted January 29, 2007 Author Share Posted January 29, 2007 Reffin' Hell By: Grant Stevens. on: 2007-22-01 03:48:27 PM Winshill U12B 4 TL Darby 2 By: paul-walters on: 2007-23-01 01:13:48 PM Reffin' Hell By: Kerry Walker on: 2007-23-01 03:57:03 AM Well done lads By: Ryan Pirrie on: 2007-21-01 08:37:07 PM Under 9 B Team lose 3-2 to Gresley - It just wasn't our day By: Kevin Smith on: 2007-20-01 11:41:35 AM Cancelled Again!!! By: Andy Ward on: 2007-20-01 09:15:52 AM Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-171843 Share on other sites More sharing options...
shoz Posted January 29, 2007 Share Posted January 29, 2007 You'll need to modify the UNION carefully if there's other information that you need for the page.[code](SELECT id, DATE, USERNAME, TITLE FROM Message)UNION ALL(SELECT ReplyID, DATE, USERNAME, TITLE FROM MessageR)ORDER BYid DESC, DATE ASC[/code]If you do a JOIN you'll have better control IMO.[code]SELECT....FROMMessageLEFT JOINMessageRONMessage.ID=MessageR.ReplyIDORDER BY Message.ID DESC, MessageR.DATE [/code] Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-171863 Share on other sites More sharing options...
fazzfarrell Posted January 29, 2007 Author Share Posted January 29, 2007 Tried both ways but I keep getting an error in dreamwaever when I test it? Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-171881 Share on other sites More sharing options...
shoz Posted January 29, 2007 Share Posted January 29, 2007 What's the error?Note that [b]If[/b] you're using DreamWeaver to generate the code I'll have to recommend you read some of the tutorials on this and other sites so that you'll be better able to write the code yourself. Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-171899 Share on other sites More sharing options...
fazzfarrell Posted January 30, 2007 Author Share Posted January 30, 2007 I now have this as a statementSELECT Message.ID, Message.`DATE`, Message.USERNAME, Message.TITLE, Message.MESSAGE, MessageR.ReplyID, MessageR.`DATE`, MessageR.USERNAME, MessageR.TITLE, MessageR.MESSAGEFROM Message JOIN MessageR ON Message.ID=MessageR.ReplyIDORDER BY Message.ID DESC, MessageR.DATEAll I need to do now is get it to show all the records not just the one that have a reply!any one!!!! Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-172647 Share on other sites More sharing options...
shoz Posted January 30, 2007 Share Posted January 30, 2007 Use a LEFTJOIN. Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-172998 Share on other sites More sharing options...
fazzfarrell Posted January 31, 2007 Author Share Posted January 31, 2007 tearing what little hair i have left out now!I now haveSELECT Message.ID, Message.`DATE`, Message.USERNAME, Message.TITLE, Message.MESSAGE, Message.NoReply FROM Message UNION ALL SELECT MessageR.ReplyID, MessageR.`DATE`, MessageR.USERNAME, MessageR.TITLE, MessageR.MESSAGE, MessageR.NoReplyFROM MessageRORDER BY DATE DESC, ID DESCThis puts everything in order except if the 'Message' table has a reference in 'MessageR' the original message in 'Message' does not appear on the page!HELP!!!! Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-173578 Share on other sites More sharing options...
fazzfarrell Posted January 31, 2007 Author Share Posted January 31, 2007 Ha ha done it, database was slightly outthanks for all your help! Link to comment https://forums.phpfreaks.com/topic/36166-order-by/#findComment-173579 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.