In case you care, here's the table structure that the Everything Chatterbox
system uses:
CREATE TABLE message (
message_id int(11) DEFAULT '0' NOT NULL auto_increment,
msgtext char(255) DEFAULT '' NOT NULL,
author_user int(11) DEFAULT '0' NOT NULL,
tstamp timestamp(14),
for_user int(11) DEFAULT '0' NOT NULL,
PRIMARY KEY (message_id),
KEY for_user (for_user)
);
This basically breaks down to:
message_id -- arbitrary AUTO_INC primary key
msgtext -- 255 chars of communication
author_user -- reference to authors's unique ID
tstamp -- timestamp set on insertion of message, used for ordering
for_user -- optional field, if left blank it's considered "chat"
if set, it becomes a "message" for whatever user ID it references
For chat, your sql query looks something like:
my $expiration_seconds = 500;
$dbh->prepare("SELECT * FROM message
WHERE for_user=0 AND unix_timestamp(now())-unix_timestamp(tstamp)
+ < $expiration_seconds ORDER BY tstamp");
then for viewing a user's specific messages:
my $UID = getUserIdSomehow();
$dbh->prepare("SELECT * FROM message
WHERE for_user=$UID ORDER BY tstamp");
It's really a pretty simple system, but it does depend on having numeric IDs that you can look up your users with.
And don't worry too much about running out of INT -- 32-bits gives you lots of room to talk.
-nate
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.