chatroom help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jade756
Forum Newbie
Posts: 4
Joined: Fri May 22, 2009 5:21 am

chatroom help

Post 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
Last edited by Benjamin on Tue May 26, 2009 10:20 am, edited 1 time in total.
Reason: Changed code type from text to php.
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: chatroom help

Post 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 />.
Post Reply