Hello everybody,

I am trying to implement a private message system into a website I am working on but I am not sure as how to do this.

I know I can use phpBB to do this but not sure on this aswell:$

I was wondering if any body could give me examples on how the table would look like as I will doing this using MySql.

Appreciate your help

Recommended Answers

All 7 Replies

Each mysql record is one message, contains the message body, title, time etc. and the users it is to and from. The user fields would optimally be references to the ids inside a user table. You can then perform queries to get all the message to a user (inbox), all messages from a user (sentbox), and whatever else you desire.

Each mysql record is one message, contains the message body, title, time etc. and the users it is to and from. The user fields would optimally be references to the ids inside a user table. You can then perform queries to get all the message to a user (inbox), all messages from a user (sentbox), and whatever else you desire.

Thanks for reply!

Would it be possible for you to explain this part please!

Each mysql record is one message, contains the message body, title, time etc. and the users it is to and from.

Thanks

Are you familiar with databases? Databases contain tables, tables contain records, or "rows". Each row has multiple "columns" of data. I am saying that each record should have information stored for each field I mentioned. Maybe you should find a good MySQL tutorial.

Also the script should validate if the real receiver is opening the message.

Are you familiar with databases? Databases contain tables, tables contain records, or "rows". Each row has multiple "columns" of data. I am saying that each record should have information stored for each field I mentioned. Maybe you should find a good MySQL tutorial.

Yes sir I am quite familiar with Databases as I worked in a company which specialised in database systems etc for my internship. But I would call myself an intermidiate as I am still learning.

Sorry I was quite sleepy last night so your advice didn't hit straight away.

The issue that I am trying to point out is that I have a two tables for my forum:

"forum" which has the following rows and columns -

+-------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------------+------+-----+---------+----------------+
| name | tinytext | NO | | NULL | |
| description | text | YES | | NULL | |
| link_type | tinytext | NO | | NULL | |
| link_id | int(10) unsigned | NO | | NULL | |
| created | datetime | YES | | NULL | |
| modified | datetime | YES | | NULL | |
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
+-------------+------------------+------+-----+---------+----------------+

and forum_post


+-------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------------+------+-----+---------+----------------+
| forum_id | int(10) unsigned | NO | | NULL | |
| author_name | tinytext | NO | | NULL | |
| reg_number | tinytext | NO | | NULL | |
| subject | tinytext | NO | | NULL | |
| body | text | NO | | NULL | |
| created | datetime | YES | | NULL | |
| modified | datetime | YES | | NULL | |
| reply_id | int(10) unsigned | YES | | NULL | |
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
+-------------+------------------+------+-----+---------+----------------+

Now I am not familiar as to how the private_messages work??

So, if you could please draw up an example table which would help me understand the working.

Thanks

Think of it as a duplicate table to the forums, its similar - just a few changes:
Heres a very basic table:
message_id: int(10), auto_increment, primary - Message ID
message_from: int(10) - ID number of the user the message is from
message_to: int(10) - ID of the user the message is to
message_title: text - Title of the message
message_content: text - Message body
message_sent: int(11) - Timestamp of the date/time the message was sent

Thats probably the bare minimum you can get away with, when the user goes to view their messages, just search the db for records where the column message_to is equal to the id of the logged in user. You can expand it to add bool values for if the message has been read or replied to for example.

Also, looking at the structure of the tables you posted, it would be beneficial to change your datetime fields to int(11) and just store the timestamp in them. This can help with performance, especially on larger databases or if you search by these values.

Think of it as a duplicate table to the forums, its similar - just a few changes:
Heres a very basic table:
message_id: int(10), auto_increment, primary - Message ID
message_from: int(10) - ID number of the user the message is from
message_to: int(10) - ID of the user the message is to
message_title: text - Title of the message
message_content: text - Message body
message_sent: int(11) - Timestamp of the date/time the message was sent

Thats probably the bare minimum you can get away with, when the user goes to view their messages, just search the db for records where the column message_to is equal to the id of the logged in user. You can expand it to add bool values for if the message has been read or replied to for example.

Also, looking at the structure of the tables you posted, it would be beneficial to change your datetime fields to int(11) and just store the timestamp in them. This can help with performance, especially on larger databases or if you search by these values.

Thanks mate for the help.....it is exactly what I was looking for.:)
Also thanks for explaining in layman's term;)

using this I will work my way up or else will be bothering experts like you's:D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.