Jump to content

Recommended Posts

Hey all,

 

I'm trying to get my site's Chat to show only the last 20 posts, but I'm not doing such a great job of it. It'll show only 20 posts, but it always shows from zero to 20, when I want it to show the most recent 20.

 

Can anybody help me out? :/

 

<?php

include "chatconnect.php";

$getnummessages="SELECT COUNT(*) as messagecount from chatmessages";

$getnummessages2=mysql_query($getnummessages) or die("blah");

$getnummessages3= mysql_result($getnummessages2, 0);

if($getnummessages3 > '21')

{

   $startrow= $getnummessages3 - '20';

}

else

{

  $startrow=0;

}

$getmsg="SELECT id, name, message, IP FROM chatmessages ORDER BY postime DESC limit $startrow,$getnummessages3";

$getmsg2=mysql_query($getmsg) or die(mysql_error());

while($row=mysql_fetch_array($getmsg2))

{

  $message=Smiley($message); //Smiley faces

   echo $row['name'];
   echo " (#";
   echo $row['IP'];
   echo ")     ";
   echo $row['message'];
   $result3 = mysql_query("SELECT moderator FROM players
              WHERE id=".$_SESSION['id']) or die(mysql_error()); 
while($row2 = mysql_fetch_array( $result3 )) {
$mod2=$row2['moderator'];}

if($mod2 == '1'){
?>

<form name="input" action="deletechatreply.php" method="post">
<input type="hidden" name="id" value="<? echo $rows['id']; ?>">
<input type="submit" value="Delete" />
</form>
<?php
}
else{}
   echo '<br><hr><br>';



}



function Smiley($texttoreplace)

{

    $smilies=array( 

    

    

    '' => "<img src='images/smile.gif'>",

    ':blush' =>"<img src='images/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')",20000);



</script>

 

Thanks if you can!

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.