Jump to content

Need help getting a Limit function to work...


Seaholme

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.