I need help figuring out how to make this into a multi-room chat so I can. But I'm having a few problems doing it. If someone could help me out a little bit that would be great. What I want is to store rooms in the database and then when a user enters different rooms it will only show messages for that room. As the roomid is stored in the database for where the message was posted. I guess it would sort of be like a forum except its a chatroom lol. I've gotten a few ideas on this worked out, but I can't get the messages to only show for that room the user in. It shows the messages for all of the rooms.
I've tried so many different things and different ways but nothing works. And most of the time when I change anything at all the iframe that the chat messages are loading in will not load or will not load any messages. And if it does load it will load and load and load on forever.
So to get the ball rolling heres the code...
<?
if (!isset($_GET['roomid'])) {
print "<br>";
} else {
$roomid = $_GET['roomid'];
}
$roomcheck="SELECT * from ch_rooms where roomid='$roomid'";
$roomcheck2=mysql_query($roomcheck) or die("Could not select chat rooms");
while($roomcheck3=mysql_fetch_array($roomcheck2))
{
echo"
<a href='chat/chat.php?roomid=$roomcheck3[roomid]' >$roomcheck3[message]</a><br>";
}
?>
<?
set_time_limit(0);
$getrows="SELECT * from ch_messages";
$getrows2=mysql_query($getrows);
$getrows3=mysql_num_rows($getrows2);
$s=$getrows3-5;
if($s<0)
{
$s=0;
}
$id=0;
while(!connection_aborted())
{
$id++;
print "<script type='text/javascript'>";
print "window.location.hash = 'm$id';";
print "</script>";
$messagecheck="SELECT * from ch_messages order by time ASC limit $s,$getrows3 ";
$messagecheck2=mysql_query($messagecheck) or die("Could not select chat messages");
while($messagecheck3=mysql_fetch_array($messagecheck2))
{
$filter="$messagecheck3[message]";
$smilies=array(
':^' => "<img src='images/icon_evil.gif'>",
':B' => "<img src='images/icon_idea.gif'>",
'lol' => "<img src='images/icon_lol.gif'>",
':M' => "<img src='images/icon_mad.gif'>",
':r' => "<img src='images/icon_redface.gif'>",
':[' => "<img src='images/icon_sad.gif'>",
':S' => "<img src='images/icon_surprised.gif'>",
':w' => "<img src='images/icon_twisted.gif'>",
'[]' => "<img src='images/icon_right.gif'>",
$filter=str_replace(array_keys($smilies), array_values($smilies),
$messagecheck3[message]);
if($messagecheck3[registered]==1)
{
print "<font color='$registeredcolor'>$messagecheck3[poster]</font>: $filter<br>";
$s++;
print "<A name='m$id'>";
}
else if($messagecheck3[registered]==0)
{
print "<font color='$unregisteredcolor'>Unregistered</font>: You can't post<br />";
$s++;
print "<A name='m$id'>";
}
}
if($s>=$getrows3)
{
print "<a name='bottom'></a>";
flush();
sleep(1);
}
}
?>
From what I can figure this iframe is not reading the roomid from the url. But then again I am also clueless on top that lol... So any help would be great, thanks in advance. 😃