Computing.Net > Forums > Web Development > SQL question

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

SQL question

Reply to Message Icon

Name: drew22299
Date: June 12, 2007 at 06:13:45 Pacific
OS: Xp Sp2
CPU/Ram: 2, 000 mhz
Product: n/a
Comment:

I have a table of usernames and passwords and other details, how can I add a table that stores messages left by other users which the user can read and reply to?



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: June 12, 2007 at 12:18:37 Pacific
Reply:

To answer your specific question:

1) create a table to store messages in
2) write one or more programs for
a) users to leave messages
b) users to read and reply to their messages


I suspect (hope) that the question that you meant to ask is much more specific, ie. How do I create a table with these fields? How do I read a mysql table from a PHP program? etc.

Good luck


0

Response Number 2
Name: drew22299
Date: June 13, 2007 at 00:41:29 Pacific
Reply:

I know how to get data and post data to a database using SQL. Is it as simple as having a primary ket for example, userId in both tables and messages in the message table would relate to that user?


0

Response Number 3
Name: Don Arnett
Date: June 13, 2007 at 07:16:53 Pacific
Reply:

"Is it as simple as having a primary ket for example, userId in both tables and messages in the message table would relate to that user?"

Basically, yes.

I would suggest something like:

USER TABLE:
userId integer primary key
- along with whatever other user info you want, like name, login/password, etc

MESSAGE INFO TABLE:
messageId integer primary key
toUserId integer (id of user the msg is TO)
fromUserId integer (id of user the msg is FROM)
- you'll probably want to have another index on the toUserId field
- there's plenty of other info that you might keep, ie receivedDateTime, hasItBeenRepliedTo, etc

MESSAGE TABLE:
messageId integer primary key
messageText large character field

For each message, you'd insert one record into each of the two message tables. For the MessageInfo table, you'd create a unique messageId and use the User IDs of the user sending the message and the user receiving the message. Then you'd insert that messageId, along with the message text into the Message table.

The MessageInfo and Message table could be one table rather than two. Two advantages of using two tables:

1) if you query the messageInfo table, you can look at the details (userIds, any other info you might add) without having to scroll thru the text of the message, which can be a pain if the text is large (1000+ chars?)

2) if a given message is meant for more than one user, you insert multiple records into the MessageInfo table but have only one copy of the message text in the Message table.

But, if you aren't worried about one message to multiple users, you could combine the two message tables.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Creating textfiles in ASP Javascript, div, visibili...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: SQL question

sql question, case insensitive LIKE www.computing.net/answers/webdevel/sql-question-case-insensitive-like/2350.html

Oracle, SQL, Access, oh my! www.computing.net/answers/webdevel/oracle-sql-access-oh-my/956.html

SQL Query - First Day of Each Week www.computing.net/answers/webdevel/sql-query-first-day-of-each-week/1255.html