in reply to Message storing problem.
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:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Message storing problem.
by salvadors (Pilgrim) on Jan 21, 2001 at 00:30 UTC |