jaymc Posted October 28, 2007 Share Posted October 28, 2007 Ok Im building a live web chat using php, mysql, javascript, ajax I am fine with sending and retreiving data in real time using ajax as the transfer protocol However, my problem, which is becoming a nightmare, is how to I display it !! Lets say the below is the chat screen, <div id="messages"> Jamie - Hello Peter = Hi Jamie = Nice Day Peter = I know </div> Lets say Jamie's next message is "What are you doing today". I can send that off to the database no problem and I can get peters live chat to pull that message in, however, how do I get it to display underneath Peter = I know As a practice I was using document.getelementbyid('messages').innerHTML = document.getelementbyid('messages').innerHTML + "<BR>What are you doing today" That works, but, lets just say the chat gets to 1000 lines, for each new message those 1000 lines have to be pulled out via javascript, a new line written to it and then printed back in the div Im not sure but I'd take a good guess at this not being optimal and will cause CPU load on the users machine What is the best way to do this! Chat messages are deleted after 1 minute, but that doesnt matter because by then they have already been sent the the users chat. Just incase you are thinking of completely repopulating there chat with every message they have sent since the chat started.. So basically, only messages sent within the last 5 seconds are picked out from the database and sent back to them.. Any help?! Really stuck! Quote Link to comment https://forums.phpfreaks.com/topic/75144-solved-populating-fresh-data/ Share on other sites More sharing options...
GingerRobot Posted October 28, 2007 Share Posted October 28, 2007 I dont think there are any options other than the two you've mentioned. You either do it via javascript, or by refreshing the whole chat window. I don't suppose either will cause a huge load - be realistic, you're not going to get 1000 lines of chat in 1 minute. Quote Link to comment https://forums.phpfreaks.com/topic/75144-solved-populating-fresh-data/#findComment-380038 Share on other sites More sharing options...
jaymc Posted October 28, 2007 Author Share Posted October 28, 2007 Really? I have seen quite a few ajax driven chatrooms surely they dont use the same method? 1: get javascript to pull in every single message 2: write the new one 3: push it all back inside a div ? I dont mean 1000 lines a minute, I mean, if they are chatting for an hour the accumulitive messages will be 1000+ At that stage, every message sent has to to the 3 stages above There has to be another solution and leave old message on the page, untouched and simply write the latest ones at the bottom Quote Link to comment https://forums.phpfreaks.com/topic/75144-solved-populating-fresh-data/#findComment-380042 Share on other sites More sharing options...
GingerRobot Posted October 28, 2007 Share Posted October 28, 2007 Not that i can think of. At the end of the day, you still have to do something with the old data, otherwise you'd end up just writing on top of all the old chat. Personally, i'd favour the option of reloading the whole chat - i could be wrong, but i think you'll find a lot of AJAX driven chats do the same. You will notice that if the chat stays idle, e.g. no one talks, the chat window will empty. That way, there's never huge amounts of data to be dealing with. Quote Link to comment https://forums.phpfreaks.com/topic/75144-solved-populating-fresh-data/#findComment-380046 Share on other sites More sharing options...
jaymc Posted October 28, 2007 Author Share Posted October 28, 2007 If someone could advise me on how well javascript can deal with holding and pushing large sets of data for instance 1000 x Hello my name is steven blah blah blah its a nice day How easy could javascript read 1000 lines, add a new line and then push it all back inside a div Quote Link to comment https://forums.phpfreaks.com/topic/75144-solved-populating-fresh-data/#findComment-380052 Share on other sites More sharing options...
jaymc Posted October 29, 2007 Author Share Posted October 29, 2007 Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/75144-solved-populating-fresh-data/#findComment-380302 Share on other sites More sharing options...
jaymc Posted October 30, 2007 Author Share Posted October 30, 2007 Resovled Quote Link to comment https://forums.phpfreaks.com/topic/75144-solved-populating-fresh-data/#findComment-381285 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.