Jump to content

Eliminate the flickering and the position remain withoul scroll up


Recommended Posts

<?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'>",

 

    ':o'=>    "<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 :)

 

 

but how im can do it for example after 30 message chat in my chat screen, then only  the scroll is available

 

22576698251301721795.jpg

 

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

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.

<?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'>",

 

    ':o'=>    "<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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.