Re: [PHP-DB] select text from a text file
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. 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? Ed - Original Message - From: Andrew Kreps [EMAIL PROTECTED] To: Ed [EMAIL PROTECTED]; php-db@lists.php.net 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 -, 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
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]; php-db@lists.php.net 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 -, 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
Re: [PHP-DB] select text from a text file
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: php-db@lists.php.net 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]; php-db@lists.php.net 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 -, 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
Re: [PHP-DB] select text from a text file
Ed wrote: 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. I see (I think) - the timestamp idea was aimed at a public general list of messages. in the case of private messages - they are always aimed at one particular user therefore in such a case a simple flag (true/false) to state whether its been viewed would probably work - or you could just delete the last grabbed message after you have selected it for output. have fun! Ed - Original Message - From: Jochem Maas [EMAIL PROTECTED] To: Ed [EMAIL PROTECTED] Cc: php-db@lists.php.net 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]; php-db@lists.php.net 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 -, 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
Re: [PHP-DB] select text from a text file
simple, add a 'read flag' column to the table, when the record is viewed, activate this flag (say 0 for unread and 1 for read) (Note: read is a mysql keyword don't use that for a column name) and then only show the ones unread bastien From: Ed [EMAIL PROTECTED] To: Andrew Kreps [EMAIL PROTECTED] CC: php-db@lists.php.net Subject: Re: [PHP-DB] select text from a text file Date: Fri, 7 Jan 2005 08:58:18 - 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. 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? Ed - Original Message - From: Andrew Kreps [EMAIL PROTECTED] To: Ed [EMAIL PROTECTED]; php-db@lists.php.net 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 -, 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] select text from a text file
Hi, I've been looking at ways todo this, and as yet haven't figured out howto pull something from the database plus at the sametime update the record, can someone tell me how this is done or where i could learn? i've looked all over phpbuilder and a few other php forums but can't seem to find the answer. Ed - Original Message - From: Bastien Koert [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Cc: php-db@lists.php.net Sent: Friday, January 07, 2005 2:06 PM Subject: Re: [PHP-DB] select text from a text file simple, add a 'read flag' column to the table, when the record is viewed, activate this flag (say 0 for unread and 1 for read) (Note: read is a mysql keyword don't use that for a column name) and then only show the ones unread bastien From: Ed [EMAIL PROTECTED] To: Andrew Kreps [EMAIL PROTECTED] CC: php-db@lists.php.net Subject: Re: [PHP-DB] select text from a text file Date: Fri, 7 Jan 2005 08:58:18 - 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. 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? Ed - Original Message - From: Andrew Kreps [EMAIL PROTECTED] To: Ed [EMAIL PROTECTED]; php-db@lists.php.net 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 -, 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] select text from a text file
On Wed, 5 Jan 2005 11:58:59 -, 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-DB] select text from a text file
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? 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.