Jump to content

php chat simple


grlayouts

Recommended Posts

Below is a peice of code for my in game chat system and it works okay, but i would like a few things and i'm not sure of how to go about it.

 

1. the most recent post to be on top i beleive i might be able to do that with the time stamp i have.

2. when people post a comment for the line spaces to show up? (simple but im not sure how)

3. when it's a set user ie = playerx the font colour to be different.

 

 

if anyone could help i'd be thankful.

 

<?php





if ($sc == "")

{

   diver ('Battle Of Species Global Game Talk');
   $sql3 = "UPDATE users SET gamechat=0 where id=$userid";

   mysql_query($sql3);

   echo '<center><BR>[<a href="index.php?cmd=chat&sc=chatadd">Add Post</a>]</center><BR><BR>';



   $sql = "SELECT id FROM comm2 WHERE parent=0 ORDER BY `time` DESC";

   $r = mysql_query($sql);

   while ($row = mysql_fetch_row($r)) 

   {

      echo '<table border="0"><tr><td>';

      showMessage($row[0], 0,$b);

      echo '</td></tr></table><BR><BR>';

   }





}else if ($sc =="chatadd")

{

   diver ('Enter Your Post Below');

   echo '<center>';

   echo '<form method="post" action="index.php?cmd=chat&sc=chatadd2">';

   echo '<input type="hidden" name="inPar" value="'.$inPar.'">';

   echo '<textarea rows="10" cols="45" name="inText" style="'.$boxStyle.'"></textarea><BR><BR><input type="submit" value="Post">';

   echo '</form></center>';

}else if ($sc == "chatadd2")

{

   diver ("Message Posted");

   $inText = clean($inText);

$sql = sprintf("INSERT INTO comm2 (author,parent,time,post) VALUES ('%s','%s','".time()."','%s')",
mysql_real_escape_string($userid),
mysql_real_escape_string($inPar),
mysql_real_escape_string($inText));

   mysql_query($sql);
   
    $sql2 = "UPDATE users SET gamechat=1";

   mysql_query($sql2);

   echo '<BR><BR><center>You message has been posted!<BR>[<a href="index.php?cmd=chat">Back to Game Chat</a>]';

}





function showMessage($m, $l, $b)

{

   global $prefDate;

   echo '<table border="0" style="font-famile: Verdana; font-size: 12px" cellpadding="4"><tr>';

   for ($i = 0; $i < $l; $i++)

   {

      echo '<td> </td>';

   }

   echo '<td>';

   $sql = "SELECT `post`,`author`,`id`,`time` FROM `comm2` WHERE `id`='{$m}'";

   $r = mysql_query($sql); $row = mysql_fetch_row($r);

   $row[0] = '<B>'.getvalue($row[1],'handle').'</B><BR>'. $row[0];

   $row[0] .= '<BR>[<a href="index.php?cmd=chat&sc=chatadd&inPar='.$row[2].'">Reply</a>] [Posted: '. date($prefDate,$row[3]) .']';
   
   
   
   
   
   

   echo str_replace('

','<BR>',$row[0]);

   echo '</td></tr></table>';

   $sql = "SELECT id FROM comm2 WHERE parent={$m} ORDER BY time DESC";

   $r = mysql_query($sql);

   while ($row = mysql_fetch_row($r))

   {

      showMessage($row[0], $l + 1, $b);

   }

}

[code]

Link to comment
Share on other sites

Tried a few things and still no joy with the above,

 

so here's a copy of the database too

 


id 	band 	parent 	time                    	post 	                                author
2 	0 	            0   	1289311197 	Hey johhny b, welcome! 	                1

Link to comment
Share on other sites

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.