jasonc Posted March 4, 2010 Share Posted March 4, 2010 I have started a chat script but face the problems in the page refreshing. at present i use the meta-refresh method which is not a good idea, stops the user from entering text and clears the text they have typed in when refresh happens. how do i get the page to refresh the textfields content if it changes, due to the other user they are chatting to entering text at they end and sending it. either user sends a new message and this is added to the database, single mysql field containing al the text from both users. user1:abc user2:def .. .. i wish for both users page to refresh if the database field has been updated. how do i do this Quote Link to comment https://forums.phpfreaks.com/topic/194141-edited-how-do-i-refresh-a-certain-forms-textfield-every-30-seconds/ Share on other sites More sharing options...
Anti-Moronic Posted March 7, 2010 Share Posted March 7, 2010 You create a javascript function which runs every x amount of seconds - this javascript function does an ajax call which retrieves all messages from the database for that chat, and using javascript to replace the current content. You can spice it up with jquery and have content fade in etc. EDIT: Sorry, think I may have misunderstood. What you do is on your ajax call, you send the current content or the length of the current content to the php script. That then compares the content or length of with what is currently in the database - if there is more, or the content is different, load the new content. But a better way is to have all messages stored in a single table with one message per row. Because no matter what, you are always going to make a mysql call. Like this: col user1 col user2 col msg then when you check for an update you send the current amount of rows for between those people which you should make available on the page. monitor(numrows){ //do ajax call } //php $msgs = mysql_query("select * from messages where user1='person1' and user2='person2'"); if(mysql_num_rows($msgs) > $CURRENTNUMROWS){ // load new content and send back to ajax } Quote Link to comment https://forums.phpfreaks.com/topic/194141-edited-how-do-i-refresh-a-certain-forms-textfield-every-30-seconds/#findComment-1022813 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.