Page 1 of 1

chatroom help

Posted: Sat May 23, 2009 9:28 pm
by jade756
i need help.. im making this simple chatroom and i want to add emoticons to the message..
pls give me an idea how to do it.. just a simple idea would do.. I couldn't find something useful about it in Google..
moreover, for example the user enters this message:

"I am happy
Are u?"

When it is displayed in the window message, here is the displayed message:
"I am happy Are u?"

how do i go about making the "Are u" text go below as inputted by the user.. I want it to appear exactly as the user inputted it..

Here is my code for displaying the message :

Code: Select all

 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<?php
        require 'db/db_connect.php';
        require 'db/session.php';   
        $id=$_SESSION['id'];
?>
</head>
<meta http-equiv="refresh" content="1">  
<body bgcolor=#ffffff>
<table id=smallfont>
<?php
    $sql1=mysql_query("SELECT maintime, chatid, message from mainchat ORDER BY maintime");
    $rows=mysql_num_rows($sql1);
    @mysql_data_seek($sql1,$rows-15);
    
    //if the number of messages<15, get all of the messages
    if ($rows<15) $l=$rows; 
    else $l=15; 
    for ($i=1;$i<=$l; $i++) {
 
        list($maintime, $chatID, $message)=mysql_fetch_row($sql1);
        $sql2=mysql_query("SELECT username from person where personID='$chatID'");
        $result2=mysql_fetch_array($sql2);
        $username=$result2[0];
        echo "<b> "; echo $username; echo":</b> &nbsp " ; echo $message; echo " <br>";
    } 
    
    //delete the old messages(only keep the newest 30 only)
 
    @mysql_data_seek($sql1,$rows-30);
    list($limtime)=mysql_fetch_row($sql1);
    $str="DELETE FROM mainchat WHERE maintime<'$limtime' ;";
    $result=mysql_query($str);
?>
</table>
</body>
</html>
 
thanks in advance

Re: chatroom help

Posted: Sun May 24, 2009 8:12 am
by watson516
For the emoticon thing in the message, you'd have to go and replace whatever text with the image before displaying it.

As for the proper spacing, you could use nl2br() function which just replaces all of the new line characters in your text with <br />.