legohalflife2man Posted June 16, 2008 Share Posted June 16, 2008 I have a chat box coded in PHP on my website that has to be refreshed each time someone enters a message. I am wondering if there is a way to make it where the chatbox.php page automatically displays new entries to the database without having to refresh the page. So, if I am on the chat box and someone enters a message, I don't want to have to refresh the chat box in order to see the new message. I want the chat box to show the newly-entered message on the chat box page without having to refresh the page. So, how can I do this? In case anyone needs the URL to my website with the chat box on it, here it is: http://generalgamingplanet.com/chat . Please tell me everything you can to help me. Quote Link to comment https://forums.phpfreaks.com/topic/110494-solved-display-new-information-from-a-database-without-refreshing-page/ Share on other sites More sharing options...
Mattyspatty Posted June 16, 2008 Share Posted June 16, 2008 i dont know if there is a way to update exactly when a new message is sent, however you should be able to use ajax to update the textarea every X seconds. try posting in the ajax forum Quote Link to comment https://forums.phpfreaks.com/topic/110494-solved-display-new-information-from-a-database-without-refreshing-page/#findComment-566885 Share on other sites More sharing options...
legohalflife2man Posted June 17, 2008 Author Share Posted June 17, 2008 Well, I want it to be like a real time chatbox, but that's OK. I changed my mind though and I want something different now: I want it to be where it refreshes each time a message is posted by someone. So, if someone other than me posts a message, I want the chatbox to refresh for everyone who is viewing it. That way, everyone gets to see the updated chat log at the same time. You know what I mean? So, I guess my new question is this: Is there any way to refresh a page once a new entry is added to the database? Quote Link to comment https://forums.phpfreaks.com/topic/110494-solved-display-new-information-from-a-database-without-refreshing-page/#findComment-566983 Share on other sites More sharing options...
fenway Posted June 17, 2008 Share Posted June 17, 2008 Like AJAX? Quote Link to comment https://forums.phpfreaks.com/topic/110494-solved-display-new-information-from-a-database-without-refreshing-page/#findComment-567329 Share on other sites More sharing options...
xtopolis Posted June 17, 2008 Share Posted June 17, 2008 There is no exact 'realtime' method using code. You can have it request data from the server every x seconds, but it would never be true real time, also it would put a strain on the server if you have many people doing this. For real time options, you might try flash since I think it creates a socket connection for its chat based apps. Quote Link to comment https://forums.phpfreaks.com/topic/110494-solved-display-new-information-from-a-database-without-refreshing-page/#findComment-567532 Share on other sites More sharing options...
haku Posted June 18, 2008 Share Posted June 18, 2008 There are some decent AJAX based chat programs out there (like this one: https://blueimp.net/ajax/#demo), so it can be done. As for how to do it, well that's beyond the scope of this thread. The first thing would be to learn the basics of how ajax works (google is your friend), and then ask some specific questions from there. Quote Link to comment https://forums.phpfreaks.com/topic/110494-solved-display-new-information-from-a-database-without-refreshing-page/#findComment-567765 Share on other sites More sharing options...
legohalflife2man Posted June 18, 2008 Author Share Posted June 18, 2008 Thanks! That's exactly what I needed. Quote Link to comment https://forums.phpfreaks.com/topic/110494-solved-display-new-information-from-a-database-without-refreshing-page/#findComment-568593 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.