shebbycs Posted October 3, 2011 Share Posted October 3, 2011 <?php $db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password if(!$db) die("no db"); if(!mysql_select_db("cute",$db)) //database name die("No database selected."); $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()); while($getmsg3=mysql_fetch_array($getmsg2)) { $getmsg3['message'] = addSmiley($getmsg3['message']); //Smiley faces print "<font color='blue'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } function addSmiley($texttoreplace) { $smilies=array( '' => "<img src='smile.gif'>", '' =>"<img src='blush.gif'>", ':angry' =>"<img src='images/angry.gif'>", ''=> "<img src='images/shocked.gif'>", 'fuck'=>"$#$%", 'Fuck'=>"&$#@" ); $texttoreplace=str_replace(array_keys($smilies), array_values($smilies), $texttoreplace); return $texttoreplace; } ?> <script> setTimeout("window.location.replace('chatlog.php')",2000); </script> actually my main question that the last section how the chat can be refresh without scrolling up and remain in exact location Quote Link to comment https://forums.phpfreaks.com/topic/248319-eliminate-the-flickering-and-the-position-remain-withoul-scroll-up/ Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 Scrolling has nothing to do with PHP, you will need to use JavaScript to control the scroll position. The way to do this would be to pass the current scroll position to the refreshed page. Quote Link to comment https://forums.phpfreaks.com/topic/248319-eliminate-the-flickering-and-the-position-remain-withoul-scroll-up/#findComment-1275145 Share on other sites More sharing options...
shebbycs Posted October 3, 2011 Author Share Posted October 3, 2011 but how im can do it for example after 30 message chat in my chat screen, then only the scroll is available but my two problem is after next message is submit im means the submit button is clicked its can scroll down and no need for user to scroll it down and second is its always reload in every 2 seconds how im can refresh the chat without removing exact position that im chatting Quote Link to comment https://forums.phpfreaks.com/topic/248319-eliminate-the-flickering-and-the-position-remain-withoul-scroll-up/#findComment-1275181 Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 If there is no scrollbar then the scroll position will be 0. From what you are saying you want to scroll the "chat area" to the bottom when a new message is posted? Quote Link to comment https://forums.phpfreaks.com/topic/248319-eliminate-the-flickering-and-the-position-remain-withoul-scroll-up/#findComment-1275184 Share on other sites More sharing options...
shebbycs Posted October 3, 2011 Author Share Posted October 3, 2011 yes since this code : setTimeout("window.location.replace('chatlog.php')",2000); will make the chat to refresh and the scroll will be up or anything that can be replaced with this code any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/248319-eliminate-the-flickering-and-the-position-remain-withoul-scroll-up/#findComment-1275185 Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 setTimeout(function() { var scrolled = document.getElementById('your_element').scrollTop; window.location = 'chat.php?top=' + scrolled; },2000); // This sets the scroll position // loading part document.getElementById('your_element').scrollTop = '<?php echo $_GET['top']; ?>'; SHOULD append the current scroll position to the URL when it reloads, using jQuery to do this is a much better option as it will work for most browers.. the loading part doesnt really work (its fine in FF but not in IE), at least it puts you on the right path. Quote Link to comment https://forums.phpfreaks.com/topic/248319-eliminate-the-flickering-and-the-position-remain-withoul-scroll-up/#findComment-1275191 Share on other sites More sharing options...
shebbycs Posted October 7, 2011 Author Share Posted October 7, 2011 <?php $db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password if(!$db) die("no db"); if(!mysql_select_db("cute",$db)) //database name die("No database selected."); $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()); while($getmsg3=mysql_fetch_array($getmsg2)) { $getmsg3['message'] = addSmiley($getmsg3['message']); //Smiley faces print "<font color='blue'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } function addSmiley($texttoreplace) { $smilies=array( '' => "<img src='smile.gif'>", '' =>"<img src='blush.gif'>", ':angry' =>"<img src='images/angry.gif'>", ''=> "<img src='images/shocked.gif'>", 'fuck'=>"$#$%", 'Fuck'=>"&$#@" ); $texttoreplace=str_replace(array_keys($smilies), array_values($smilies), $texttoreplace); return $texttoreplace; } ?> <script> setTimeout(function() { var scrolled = document.getElementById('your_element').scrollTop; window.location = 'chatlog.php?top=' + scrolled;},2000); // This sets the scroll position // loading part document.getElementById('your_element').scrollTop = "<?php echo $_GET['top']; ?>"; </script> what is wrong in this pla pliz check it because it seems the chat is not refresh sir Quote Link to comment https://forums.phpfreaks.com/topic/248319-eliminate-the-flickering-and-the-position-remain-withoul-scroll-up/#findComment-1276670 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.