Jump to content
xisto Community
Feelay

How To Make A PM (Personal Message) System? (Should I Store The Data In A Database?)

Recommended Posts

Hey! I just wanted to know, if I want to make a PM system, should I store the PMs in a database or how should I do it? And if I should store them in a database, how do I do that. Because I have acctually no idea, if I should create 50 tables to store 50 messages ;)(And a little OT question[instead of creating a new topic]).How can i change the timestamp [time()] into real date?

Edited by Feelay (see edit history)

Share this post


Link to post
Share on other sites

In short, yes!

You would save PM's in the database...

You create a table in your database with at least 4 columns (fields) then each message gets its own row (record).

I suggest the following columns:
message_id
user_id_from
user_id_to
message_title
message_contents
message_date
message_read

The first is the id of the message which should be incremented in MySQL each message. (1,2,3,...)
The second is the user id (username, id number, whatever) of the sender of the message.
The third is the user id (username, id number, whatever) of the recipient of the message.
The forth is the title of the message.
The fifth is the actual contents of the message. (message body)
Sixth is the date which the message was sent.
Finally, seventh is a flag as to whether or not the message has been read. (Yes | No) OR (1 | 0)

The system is actually very simple to code and I have confidence that you will be able to do it.
I wouldn't try doing a filing system for PM's and when a user deletes a message, then remove it from the database.
The new message alert would just be a database query to find any messages with the user's ID being the same as the user_id_to and that hasn't been marked as read.

Now for your time issue...

The PHP manual does a very good job of explaining how to use time and date functions. Here is the link:
http://us.php.net/manual/en/function.date.php

One thing to consider, if you are using a UNIX timestamp (seconds since 1/1/1970) then you enter that as the second argument of the data function like so:

echo date("F j, Y, g:i a", 3600);				 // January 1, 1970, 1:00 am
Because, 3600 seconds is 1 hour from the Epoch (1/1/1970)!

Likewise, this is what you would use for the date of January 5, 1970 at 2:34 pm:
echo date("F j, Y, g:i a", 484440);				 // January 5, 1970, 2:34 pm
Because, 484440 seconds is 5 days 14 hours and 34 minutes from the Epoch!

There are many formate examples on the page I linked to as well as a complete listing of every date code you can use with the date function.

Hope this helps. ;)

vujsa

Share this post


Link to post
Share on other sites

Thanks alot Vujsa :P ! Now I have made a version 0.1 PM script. I'll make a tutorial about it someday :P And as you said, it was very easy to make the script :P just took me 3 hours ;)Thanks again //Feelay

Edited by Feelay (see edit history)

Share this post


Link to post
Share on other sites

OK I AM A KID. BUT I OWN A SITE. BUT I KNOW ONLY HTML AND JAVA, NOT DATABASES. COULD ANYONE MAKE A TUTORIAL ON DATABASES? THE WORLD WILL LIKE IT.
How To Make A PM (Personal Message) System?

I own a site. But I use form systems for it. Presently, I am only 13 years old.
By the way, I first designed my site on notepad with HTML, but forgot about publishing. Then I moved to GPC.

Someone please teach me of databases. I would greatly appreciate it.
By the way. The searches do not provide sufficient explanations on databases!

Thank you!

-reply by Thauwa



Share this post


Link to post
Share on other sites

In short, yes!
You would save PM's in the database...

You create a table in your database with at least 4 columns (fields) then each message gets its own row (record).

I suggest the following columns:
message_id
user_id_from
user_id_to
message_title
message_contents
message_date
message_read

The first is the id of the message which should be incremented in MySQL each message. (1,2,3,...)
The second is the user id (username, id number, whatever) of the sender of the message.
The third is the user id (username, id number, whatever) of the recipient of the message.
The forth is the title of the message.
The fifth is the actual contents of the message. (message body)
Sixth is the date which the message was sent.
Finally, seventh is a flag as to whether or not the message has been read. (Yes | No) OR (1 | 0)

The system is actually very simple to code and I have confidence that you will be able to do it.
I wouldn't try doing a filing system for PM's and when a user deletes a message, then remove it from the database.
The new message alert would just be a database query to find any messages with the user's ID being the same as the user_id_to and that hasn't been marked as read.

Now for your time issue...

The PHP manual does a very good job of explaining how to use time and date functions. Here is the link:
http://us.php.net/manual/en/function.date.php

One thing to consider, if you are using a UNIX timestamp (seconds since 1/1/1970) then you enter that as the second argument of the data function like so:

echo date("F j, Y, g:i a", 3600);				 // January 1, 1970, 1:00 am
Because, 3600 seconds is 1 hour from the Epoch (1/1/1970)!

Likewise, this is what you would use for the date of January 5, 1970 at 2:34 pm:
echo date("F j, Y, g:i a", 484440);				 // January 5, 1970, 2:34 pm
Because, 484440 seconds is 5 days 14 hours and 34 minutes from the Epoch!

There are many formate examples on the page I linked to as well as a complete listing of every date code you can use with the date function.

Hope this helps. :mellow:

vujsa
sign me up and create a template for me with login scripts.

Share this post


Link to post
Share on other sites

Yes, you should use a database, one way of setting it out would be tohave 2 tables for each user. 1 for incoming messages, one for outgoing.The incoming table's columns could be - subject - sender - date sent - status (read unread or replied) - message contentThe outgoings table's columns could be - subject - user message is to - date received - read, unread or reply received - message contentOr you could merge the two, and have columns like these: - sender - receiving user - subject - date sent - read, unread or replied - message content - message type (sent or received)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.