send messages to other users need help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

send messages to other users need help

Post by scarface222 »

Hey guys just wondering if anyone knows the best way to set up a system that allows users to send messages to eachother. I figured using a mysql table with the users name and 10 fields for messages but it doesn't make sense for obvious reasons. Is there a way to set it up so when a message is sent there is a spot created for it without creating a field for the entire table or a different practical way? I know this may sound dumb to some but I am rather inexperienced still so bare with me.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: send messages to other users need help

Post by requinix »

Code: Select all

userid | username
-------+---------
     1 | Alice
     2 | Bob
     3 | Cindy
     4 | David
 
fromuser | touser | subject                           | message
---------+--------+-----------------------------------+-------------------------------------------------
       3 |      1 | Bob                               | Bob's kinda cool. What's he like?
       1 |      3 | Re: Bob                           | He's a nice guy. You should talk to him sometime
       1 |      2 | Cindy                             | I think Cindy likes you. Invite her to dinner!
       2 |      4 | What do you know about Cindy?     | So I heard that Cindy's interested in me...
       4 |      3 | Bob's asking about you            | You like him?
       3 |      4 | Re: Bob's asking about you        | I dunno... maybe...
       4 |      2 | Re: What do you know about Cindy? | Go for it!
       2 |      3 | Hey                               | You busy Saturday night?
       3 |      1 | Re: Bob                           | Alice! He asked me out!
       1 |      3 | Re: Bob                           | Great! You'll have to tell me about it
       3 |      2 | Re: Hey                           | Nah, I'm free. Wanna do something?
...
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: send messages to other users need help

Post by scarface222 »

Thanks I will test it out. Just curious, when you use a primary and foreign key ie. userid it automatically links two tables? How do you set up that link using say phpmyadmin?
Post Reply