MySQL query and PHP

Discussion in 'PHP' started by karl_murphy, Mar 20, 2008.

  1. #1
    I am trying to develop a simple messaging system. I have already developed the relevant sections to be able to send and recieve messages, but I am have trouble creating the "Sent items" area. Basically this section will allow the user to view the messages they have sent.

    I have set up three tables to facilitate the messaging system and they are as follows:

    Mail

    MA_ID
    MA_Subject
    MA_Message
    MA_Date

    Mail_Inbox

    MI_MA_ID
    MI_Recipient

    Mail_Sent

    MS_MA_ID
    MS_Sender


    If you can imagine user A sending a couple of messages to two other users. This is how the tables are populated:

    Mail

    MA_ID- - - MA_Subject- - -MA_Message- - -MA_Date
    1 - - - - - - - Subject A - - - - Message A - - - - 01/01/2008
    2 - - - - - - - Subject B - - - - Message B - - - - 02/01/2008


    Mail_Inbox

    MI_MA_ID - - - MI_Recipient
    1 - - - - - - - - - - - - B
    1 - - - - - - - - - - - - C
    2 - - - - - - - - - - - - B
    2 - - - - - - - - - - - - C


    Mail_Sent

    MS_MA_ID - - - MS_Sender
    1 - - - - - - - - - - - - A
    2 - - - - - - - - - - - - A


    I want to set up an area where a user can view the messages they have sent. For this example, if user A logged in and wanted to see the messages they had sent, I would want it to look something like the following:

    To - - - Date - - - Subject
    B, C - - 01/01/2008 - - Subject A
    B, C - - 02/01/2008 - - Subject B

    I'm having problems writing a query to exact this data aswel problems writing code to display it in this way.

    Any ideas?
     
    karl_murphy, Mar 20, 2008 IP