| |
Welcome to the dBforums forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact contact support.
If you prefer not to see double-underlined words and corresponding ads, place your cursor here for ContentLink opt out.
|
 |
|

09-17-07, 07:51
|
|
Registered User
|
|
Join Date: Jun 2007
Location: London
Posts: 108
|
|
|
PM System
|
Hello all,
I am creating a forum from scratch and i have go to the stage where i want to create a private messaging system, just like the one we have in this forum.
So my idea is to have a table called messages with fields such as usersent and userreceived. This means i will search for each user their messages from this table. Is this efficient? Is there a better way?
Thanks all, I appreciate any help.
|
|

09-17-07, 08:14
|
|
SQL Apprentice
|
|
Join Date: Jan 2007
Location: hiding
Posts: 8,143
|
|
This would seem fairly efficient...
One message can be sent by one user to one user
Code:
--all messages to one user (inbox)
SELECT msgID
, userSent
, msgTitle
, replied
, read
, dateSent
FROM messages
WHERE userTo = 'compsci'
--Sent messages for one user (sent items)
SELECT msgID
, userTo
, msgTitle
, dateSent
FROM messages
WHERE userSent = 'compsci'
One thing it does limit you is that you can only send one message to one user at a time.
__________________
George
You only stop learning when you stop asking questions.
|
|

09-17-07, 08:26
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,556
|
|
|
Quote:
|
Originally Posted by georgev
One thing it does limit you is that you can only send one message to one user at a time.
|
each message to only one user ever
|
|

09-17-07, 08:50
|
|
Registered User
|
|
Join Date: Jun 2007
Location: London
Posts: 108
|
|
Quote:
|
Originally Posted by r937
each message to only one user ever
|
Is this what you mean georgev?
|
|

09-17-07, 09:01
|
|
SQL Apprentice
|
|
Join Date: Jan 2007
Location: hiding
Posts: 8,143
|
|
Nope; I mean that you can only send one message at a time to one recipient.
I don't follow what Rudy is getting at I'm afraid!
__________________
George
You only stop learning when you stop asking questions.
|
|

09-17-07, 09:03
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,556
|
|
if the table has usersent and userreceived, then each message can be sent to only one user
ever
perhaps you could explain what you meant by "one at a time"
|
|

09-17-07, 09:36
|
|
Registered User
|
|
Join Date: Jun 2007
Location: London
Posts: 108
|
|
Quote:
|
Originally Posted by r937
if the table has usersent and userreceived, then each message can be sent to only one user
ever
|
The above fields [usersent and userreceived] are what i declared. The table i am creating will not contain those fields only. My idea, is that when a user sends a message. The fields of who sent it and who the sender is sending to are both recorded by the messages table.
So when someone checks there inbox. I will test who is logged in and based on this:
"SELECT from messages WHERE userrceived='$loggedonuser'"
and for the outbox:
"SELECT from messages WHERE usersent='$loggedonuser'"
So this meas a user can receive many emails and send many emails.
|
|

09-17-07, 09:43
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,556
|
|
can a user send a PM to more than one other user?
with your current setup, he would have to send separate messages, which means that there would be multiple rows identical in everything except the recipient, which would actually bloat the table and inflate the message count
|
|

09-17-07, 09:56
|
|
SQL Apprentice
|
|
Join Date: Jan 2007
Location: hiding
Posts: 8,143
|
|
That was my point 
__________________
George
You only stop learning when you stop asking questions.
|
|

09-17-07, 10:01
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,556
|
|
yeah, but your point ("... to one user at a time") gives the false impression that you can send the same message to another user later
and my point is that it isn't the same message!!!

|
|

09-17-07, 10:08
|
|
Registered User
|
|
Join Date: Jun 2007
Location: London
Posts: 108
|
|
Quote:
|
Originally Posted by r937
can a user send a PM to more than one other user?
with your current setup, he would have to send separate messages, which means that there would be multiple rows identical in everything except the recipient, which would actually bloat the table and inflate the message count
|
--> I guess yor talking about georgev setup??
|
|

09-17-07, 10:13
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,556
|
|
no, i'm talking about your setup, compsci
|
|

09-17-07, 10:30
|
|
Registered User
|
|
Join Date: Jun 2007
Location: London
Posts: 108
|
|
Quote:
|
Originally Posted by r937
no, i'm talking about your setup, compsci
|
lol ok
Well for my setup you can send to different users.
If a user wishes to send a message then they will enter the username they wish to send to [which will go in the "userreceived" field]. They have a choice of all registered users of course. This means that they can send to different people!
Those who wish to recieve their messages will got to their inbox and i will use a statement like this:
"SELECT from messages WHERE userreceived='$loggedonuser'"
and for the outbox:
"SELECT from messages WHERE usersent='$loggedonuser'"
-So i can send to multiple users one at a time or even many users at a time, since all i have to do is create a row for each user its being sent to.
Is this clear? Am i missing something?
|
|

09-17-07, 10:33
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,556
|
|
so you can only send a message to one user, right?
|
|

09-17-07, 10:41
|
|
Registered User
|
|
Join Date: Jun 2007
Location: London
Posts: 108
|
|
Quote:
|
Originally Posted by r937
so you can only send a message to one user, right?
|
No, i can send to many.
To: john, paul, david
From: compsci
Message: ~~
Now i will create 3 rows for the above, since there are three people and for each of these people to receive their messages the query will look like this:
Code:
"SELECT from messages WHERE userreceived='john'"
"SELECT from messages WHERE userreceived='paul'"
"SELECT from messages WHERE userreceived='david'"
So i can send to many people at different times and i can also send to many people at the same time. Where they get the same message.
Is my logic flawed?
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|