shebbycs Posted December 6, 2011 Share Posted December 6, 2011 <?php $db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password mysql_select_db("cute") or die(mysql_error()); $getnummessages="SELECT COUNT(*) as messagecount from chatmessages"; $getnummessages2=mysql_query($getnummessages) or die("blah"); $getnummessages3= mysql_result($getnummessages2, 0); if($getnummessages3>40) { $startrow=$getnummessages3-20; } else { $startrow=0; } $getmsg="SELECT name, message from chatmessages order by postime ASC limit $startrow,$getnummessages3"; $getmsg2=mysql_query($getmsg) or die(mysql_error()); function replacesmiley($msg) { $msg = str_replace('', '<img src="smile.gif" alt="" />', $msg); $msg = str_replace('', '<img src="sad.gif" alt="" />', $msg); $msg = str_replace('', '<img src="tongue.gif" alt="" />', $msg); return $msg; } echo replacesmiley($text); function filterBadWords($str) { $result = mysql_query("SELECT badwords FROM clean") or die(mysql_error()); $replacements = "*"; while($row = mysql_fetch_assoc($result)) { $str = eregi_replace($row['badwords'], str_repeat('*', strlen($row['badwords'])), $str); } return $str; } while($getmsg3=mysql_fetch_array($getmsg2)) { $getmsg3['message'] = replacesmiley($getmsg3['message']); $getmsg3['message'] = filterBadWords($getmsg3['message']); //Smiley faces print "<font color='blue'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } ?> <script> setTimeout("window.location.replace('chatlog.php')",2000); </script> how to do when chat screen refresh its does not reload to the top of page and stay to where user are browse Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/ Share on other sites More sharing options...
ZulfadlyAshBurn Posted December 6, 2011 Share Posted December 6, 2011 by using ajax ? Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295003 Share on other sites More sharing options...
shebbycs Posted December 6, 2011 Author Share Posted December 6, 2011 by using ajax ? if im using ajax how i can put it show me solution please Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295006 Share on other sites More sharing options...
ZulfadlyAshBurn Posted December 6, 2011 Share Posted December 6, 2011 what is your question? cause it isn't clear o.0 Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295007 Share on other sites More sharing options...
ManiacDan Posted December 6, 2011 Share Posted December 6, 2011 This page refreshes itself after a few seconds. Don't do that. Either let the user refresh it manually or use ajax to refresh all the data in the chart. If you choose to use ajax, be prepared to LEARN AJAX, completely rewrite this page, and spend about 2 weeks on it at minimum. There isn't just a "put the ajax right here" we can give you. Ajax is a whole different way of thinking about content generation. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295017 Share on other sites More sharing options...
shebbycs Posted December 7, 2011 Author Share Posted December 7, 2011 what is your question? cause it isn't clear o.0 this code " setTimeout("window.location.replace('chatlog.php')",2000);" will refresh but as its refresh the scroll going to be top as im want it to be where people scroll it even after refresh the place to scroll is same and not going top, this is my problem ;( Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295188 Share on other sites More sharing options...
imperium2335 Posted December 7, 2011 Share Posted December 7, 2011 Why don't you just stream the output from the database into a div using setInterval every second? Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295196 Share on other sites More sharing options...
imperium2335 Posted December 7, 2011 Share Posted December 7, 2011 For your setup specifically, you could use jquery to scroll the page to the bottom on page load. Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295199 Share on other sites More sharing options...
shebbycs Posted December 7, 2011 Author Share Posted December 7, 2011 Why don't you just stream the output from the database into a div using setInterval every second? really im din get you if you can show me example im can try it Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295247 Share on other sites More sharing options...
imperium2335 Posted December 7, 2011 Share Posted December 7, 2011 <div id="AJAXstuffgoeshere"></div> <script> $.post('myphpfile.php', {var1:abc, var2:'a string'}, function(data){ $('#AJAXstuffgoeshere').html(data); }) </script> Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295248 Share on other sites More sharing options...
shebbycs Posted December 7, 2011 Author Share Posted December 7, 2011 <div id="AJAXstuffgoeshere"></div> <script> $.post('myphpfile.php', {var1:abc, var2:'a string'}, function(data){ $('#AJAXstuffgoeshere').html(data); }) </script> but still im cannot understand do you has exmaple where chatscreen is refresh using ajax thank you Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295258 Share on other sites More sharing options...
ZulfadlyAshBurn Posted December 7, 2011 Share Posted December 7, 2011 do you have a live site where we can see the code running? So, my understanding of what you want is to have to have a chat log on the page and have it refreshed every 2 seconds. If you were handling more than 100 clients, I wouldn't encourage that. What you should actually do is to check if there is any updates on the chat log. If there is then you should update the chat log. What imperium2335 had done was using jQuery's $.post() function. Learn some jQuery here From what I see, you don't speak English fluently, but hopes that site helps you. If you want people to help you code your script, you can find them or post a new topic for help. Usually there are some charges from $0++ Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295267 Share on other sites More sharing options...
shebbycs Posted December 7, 2011 Author Share Posted December 7, 2011 do you have a live site where we can see the code running? So, my understanding of what you want is to have to have a chat log on the page and have it refreshed every 2 seconds. If you were handling more than 100 clients, I wouldn't encourage that. What you should actually do is to check if there is any updates on the chat log. If there is then you should update the chat log. What imperium2335 had done was using jQuery's $.post() function. Learn some jQuery here From what I see, you don't speak English fluently, but hopes that site helps you. If you want people to help you code your script, you can find them or post a new topic for help. Usually there are some charges from $0++ better im give the screenshot ok the first and second picture is chat screen where after im using this code <script> setTimeout("window.location.replace('chatlog.php')",2000); </script> it will refresh to the picture 3 im hope you can get my problem question zul ;( as im want it refresh to where im scrolling and not after it refresh it will be going to top Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295276 Share on other sites More sharing options...
ZulfadlyAshBurn Posted December 7, 2011 Share Posted December 7, 2011 From the images, i see that you are using a div for the chat log. give the chatlog div an id for example <div id="chatlog"><?php your stuffs here ?></div> then add this script to the bottom of the script. <script> var objDiv = document.getElementById("chatlog"); objDiv.scrollTop = objDiv.scrollHeight; </script> Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295291 Share on other sites More sharing options...
shebbycs Posted December 7, 2011 Author Share Posted December 7, 2011 From the images, i see that you are using a div for the chat log. give the chatlog div an id for example <div id="chatlog"><?php your stuffs here ?></div> then add this script to the bottom of the script. var objDiv = document.getElementById("chatlog"); objDiv.scrollTop = objDiv.scrollHeight; ya i try to code Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295294 Share on other sites More sharing options...
ZulfadlyAshBurn Posted December 7, 2011 Share Posted December 7, 2011 try this. hope it works. <?php $db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password mysql_select_db("cute") or die(mysql_error()); $getnummessages="SELECT COUNT(*) as messagecount from chatmessages"; $getnummessages2=mysql_query($getnummessages) or die("blah"); $getnummessages3= mysql_result($getnummessages2, 0); if($getnummessages3>40) { $startrow=$getnummessages3-20; } else { $startrow=0; } $getmsg="SELECT name, message from chatmessages order by postime ASC limit $startrow,$getnummessages3"; $getmsg2=mysql_query($getmsg) or die(mysql_error()); function replacesmiley($msg) { $msg = str_replace('', '<img src="smile.gif" alt="" />', $msg); $msg = str_replace('', '<img src="sad.gif" alt="" />', $msg); $msg = str_replace('', '<img src="tongue.gif" alt="" />', $msg); return $msg; } echo replacesmiley($text); function filterBadWords($str) { $result = mysql_query("SELECT badwords FROM clean") or die(mysql_error()); $replacements = "*"; while($row = mysql_fetch_assoc($result)) { $str = eregi_replace($row['badwords'], str_repeat('*', strlen($row['badwords'])), $str); } return $str; } echo "<div id='chatlog'>"; while($getmsg3=mysql_fetch_array($getmsg2)) { $getmsg3['message'] = replacesmiley($getmsg3['message']); $getmsg3['message'] = filterBadWords($getmsg3['message']); //Smiley faces print "<font color='blue'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } echo "</div>"; ?> <script> setTimeout("window.location.replace('chatlog.php')",2000); var objDiv = document.getElementById("chatlog"); objDiv.scrollTop = objDiv.scrollHeight; </script> Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295295 Share on other sites More sharing options...
shebbycs Posted December 7, 2011 Author Share Posted December 7, 2011 <div id="chatlog"><?php $db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password mysql_select_db("cute") or die(mysql_error()); $getnummessages="SELECT COUNT(*) as messagecount from chatmessages"; $getnummessages2=mysql_query($getnummessages) or die("blah"); $getnummessages3= mysql_result($getnummessages2, 0); if($getnummessages3>40) { $startrow=$getnummessages3-20; } else { $startrow=0; } $getmsg="SELECT name, message from chatmessages order by postime ASC limit $startrow,$getnummessages3"; $getmsg2=mysql_query($getmsg) or die(mysql_error()); function replacesmiley($msg) { $msg = str_replace('', '<img src="smile.gif" alt="" />', $msg); $msg = str_replace('', '<img src="sad.gif" alt="" />', $msg); $msg = str_replace('', '<img src="tongue.gif" alt="" />', $msg); return $msg; } echo replacesmiley($text); function filterBadWords($str) { $result = mysql_query("SELECT badwords FROM clean") or die(mysql_error()); $replacements = "*"; while($row = mysql_fetch_assoc($result)) { $str = eregi_replace($row['badwords'], str_repeat('*', strlen($row['badwords'])), $str); } return $str; } while($getmsg3=mysql_fetch_array($getmsg2)) { $getmsg3['message'] = replacesmiley($getmsg3['message']); $getmsg3['message'] = filterBadWords($getmsg3['message']); //Smiley faces print "<font color='blue'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } ?></div> <script> var objDiv = document.getElementById("chatlog"); objDiv.scrollTop = objDiv.scrollHeight; </script> Which im left the part to refresh zul sir? Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295298 Share on other sites More sharing options...
ZulfadlyAshBurn Posted December 7, 2011 Share Posted December 7, 2011 don't worry, you can talk to me in malay. I understand malay. I dont get "Which im left the part to refresh zul sir?" o.0 Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295302 Share on other sites More sharing options...
shebbycs Posted December 7, 2011 Author Share Posted December 7, 2011 <div id="chatlog"><?php $db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password mysql_select_db("cute") or die(mysql_error()); $getnummessages="SELECT COUNT(*) as messagecount from chatmessages"; $getnummessages2=mysql_query($getnummessages) or die("blah"); $getnummessages3= mysql_result($getnummessages2, 0); if($getnummessages3>40) { $startrow=$getnummessages3-20; } else { $startrow=0; } $getmsg="SELECT name, message from chatmessages order by postime ASC limit $startrow,$getnummessages3"; $getmsg2=mysql_query($getmsg) or die(mysql_error()); function replacesmiley($msg) { $msg = str_replace('', '<img src="smile.gif" alt="" />', $msg); $msg = str_replace('', '<img src="sad.gif" alt="" />', $msg); $msg = str_replace('', '<img src="tongue.gif" alt="" />', $msg); return $msg; } echo replacesmiley($text); function filterBadWords($str) { $result = mysql_query("SELECT badwords FROM clean") or die(mysql_error()); $replacements = "*"; while($row = mysql_fetch_assoc($result)) { $str = eregi_replace($row['badwords'], str_repeat('*', strlen($row['badwords'])), $str); } return $str; } while($getmsg3=mysql_fetch_array($getmsg2)) { $getmsg3['message'] = replacesmiley($getmsg3['message']); $getmsg3['message'] = filterBadWords($getmsg3['message']); //Smiley faces print "<font color='blue'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } ?></div> <script> setTimeout("window.location.replace('chatlog.php')",2000); var objDiv = document.getElementById("chatlog"); objDiv.scrollTop = objDiv.scrollHeight; </script> is this right? Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295304 Share on other sites More sharing options...
ZulfadlyAshBurn Posted December 7, 2011 Share Posted December 7, 2011 You can also you that. it works both way. Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295306 Share on other sites More sharing options...
shebbycs Posted December 7, 2011 Author Share Posted December 7, 2011 You can also you that. it works both way. but stilll after the 2000 second it refresh and move to the top ;( any wrong ? Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295307 Share on other sites More sharing options...
ZulfadlyAshBurn Posted December 7, 2011 Share Posted December 7, 2011 well, it works for me. you can try this. <?php $db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password mysql_select_db("cute") or die(mysql_error()); $getnummessages="SELECT COUNT(*) as messagecount from chatmessages"; $getnummessages2=mysql_query($getnummessages) or die("blah"); $getnummessages3= mysql_result($getnummessages2, 0); if($getnummessages3>40) { $startrow=$getnummessages3-20; } else { $startrow=0; } $getmsg="SELECT name, message from chatmessages order by postime ASC limit $startrow,$getnummessages3"; $getmsg2=mysql_query($getmsg) or die(mysql_error()); function replacesmiley($msg) { $msg = str_replace('', '<img src="smile.gif" alt="" />', $msg); $msg = str_replace('', '<img src="sad.gif" alt="" />', $msg); $msg = str_replace('', '<img src="tongue.gif" alt="" />', $msg); return $msg; } echo replacesmiley($text); function filterBadWords($str) { $result = mysql_query("SELECT badwords FROM clean") or die(mysql_error()); $replacements = "*"; while($row = mysql_fetch_assoc($result)) { $str = eregi_replace($row['badwords'], str_repeat('*', strlen($row['badwords'])), $str); } return $str; } while($getmsg3=mysql_fetch_array($getmsg2)) { $getmsg3['message'] = replacesmiley($getmsg3['message']); $getmsg3['message'] = filterBadWords($getmsg3['message']); //Smiley faces print "<font color='blue'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } ?> <script> setTimeout("window.location.replace('chatlog.html')",2000); var objDiv = document.body; objDiv.scrollTop = objDiv.scrollHeight; </script> Quote Link to comment https://forums.phpfreaks.com/topic/252595-how-to-make-the-chat-refresh-without-going-to-top-and-stay-where-its-belong/#findComment-1295313 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.