Hi, The timestamp idea is an intresting idea and i'll give that method some thought. I only want it to pull one private message at a time out of the private message field so it might start getting very messy doing that method - but it certainly does make it worth considering.
Ed ----- Original Message ----- From: "Jochem Maas" <[EMAIL PROTECTED]> To: "Ed" <[EMAIL PROTECTED]> Cc: <firstname.lastname@example.org> Sent: Friday, January 07, 2005 11:37 AM Subject: Re: [PHP-DB] select text from a text file > Ed wrote: > > Hi, > > > > Thanks for answering the question. > > > > I'm going to make it write to a database rather than text file after > > searching google and coming accross common problems with text files. > > > > I've now just got to figure out how to mark the message as read in the > > database so it does not re-appear next time the user clicks update. > > TIMESTAMP? you can save in the session when a use last grabbed messages > (clicked update) and only return newer messages (i.e. message have a > 'created' timestamp) then update the timestamp in the session. there is > a window in which it is possible to have a request inserts a new message > in between another request's selecting of all new messages and updating > the session timestamp value (in such cases the person at the client end > of the second request will never see the new message insert in the first > request) - to handle that you have to implement some kind of locking > mechanism. > > good luck is all can say. (PHP implements a 'share nothing' architecture > - not, perse, the easiest or most efficient type of system to build > realtime multi-user environments in - AFAICT) > > > > > I'm going to build a function that will put the message in the correct table > > using an if clause, is that the best method? > > your the best judge of that - heh if it works that's the main thing - > making it work fast that's something to look at later... and then there > is the issue of writing code that neat, tidy, well commented and > readable 6 months down the line. > > > > > Ed > > ----- Original Message ----- > > From: "Andrew Kreps" <[EMAIL PROTECTED]> > > To: "Ed" <[EMAIL PROTECTED]>; <email@example.com> > > Sent: Thursday, January 06, 2005 6:55 PM > > Subject: Re: [PHP-DB] select text from a text file > > > > > > > >>On Wed, 5 Jan 2005 11:58:59 -0000, Ed <[EMAIL PROTECTED]> wrote: > >> > >>>Happy new year folks! > >>> > >>>The titlemight make this seem like an easy to answer question > >>> > >>>However here's the complicated bit (well for me anyway). > >>> > >>>In my text file that is written to by the users in a chatroom it looks > > > > like this: > > > >>>nickname||color||what the user is saying||user > >>> > >>>how can i make it so that if they have a private message when they press > > > > update it pulls the message from the text file and displays it in the frame > > but also deletes the text? > > > >>You should be using a database for this, it makes things so much > >>easier. That being said, here's one way to go about the text file > >>version: > >> > >>Open the file, read through it line by line. > >>As you read it, push the lines into an array. > >>If you find a private message for the user, store that in a variable, > >>and do not push it into the array. > >>Finish reading the file. > >>If there's a private message, you've got it in a variable, and you can > >>overwrite the private message file with the array you've stored, which > >>is all of the current private messages minus the one you're about to > >>display. > >> > >>Please note, this does not scale at all, especially in the fast-paced > >>world of chat rooms. You will likely end up with file locking > >>problems if you proceed with the flat-file method. > >> > >> > >> > >>>Also, how can i make it so that if in a drop down menu they select the > > > > word "everybody" it goes to a file called messages.txt and if they select > > "user" or "user2" or "user3" from the list it writes to private.txt is this > > at all possible? user and user2 etc arent hardcoded it's pulling the names > > from a list of online users. > > > >>Are you talking about appending messages to a text file? In that > >>case, you can have the dropdown submit with the message, and in the > >>PHP code have a case for 'everybody' where it writes to messages.txt, > >>and if it's not 'everybody', write it to private.txt with the username > >>that was selected from the dropdown as part of the row. > >> > >>Does that answer your question? > >> > >>-- > >>PHP Database Mailing List (http://www.php.net/) > >>To unsubscribe, visit: http://www.php.net/unsub.php > >> > >> > > > > > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php