[php]
<?php
session_start() ;
/*CHAT DISPLAY*/
/*
Data for $chatray...
0 = id
1 = who
2 = towho
3 = type
4 = message
5 = when
6 = x
7 = y
8 = z
*/
$clear=$_SESSIO N['clear'];
$namechat="SELE CT * FROM `logs` WHERE `when`>='$clear ' AND `x`='$x' AND `y`='$y' AND `z`='$z' AND `month`='$month ' AND `day`='$day' AND `year`='$year'" ;
$querychat=mysq l_query($namech at);
while ($chatray=mysql _fetch_array($q uerychat)) {
/***********Stan dard Display******** ***/
if ($chatray[2]==NULL) {
switch ($chatray[3]) {
//Emote
case "/":
if ($chatray[1]==$user) {
//If the user is the one that posted...
$chatdisp=$chat disp."<b>You ".$chatray[4]."</b><br>";
} elseif ($chatray[1]!=$user) {
//elseif the user is not the one that posted...
$chatdisp=$chat disp.ucfirst($c hatray[1])." ".$chatray[4]."<br>";
}
break;
//Say
case "say":
if ($chatray[1]==$user) {
$chatdisp=$chat disp."<b>You said, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user) {
$chatdisp=$chat disp.ucfirst($c hatray[1])." said, \"".$chatray[4]."\"<br>";
}
break;
//Shout
case "shout":
if ($chatray[1]==$user) {
$chatdisp=$chat disp."<b>You shouted, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user) {
$chatdisp=$chat disp.ucfirst($c hatray[1])." shouted, \"".$chatray[4]."\"<br>";
}
break;
//Say OOCLY
case "sayooc":
if ($chatray[1]==$user) {
$chatdisp=$chat disp."<b>You said OOCly, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user) {
$chatdisp=$chat disp.ucfirst($c hatray[1])." said OOCly, \"".$chatray[4]."\"<br>";
}
break;
//OOC Emote
case "ooc":
if ($chatray[1]==$user) {
$chatdisp=$chat disp."<b>You OOCly ".$chatray[4]."</b><br>";
} elseif ($chatray[1]!=$user) {
$chatdisp=$chat disp.ucfirst($c hatray[1])." OOCly ".$chatray[4]."<br>";
}
break;
}
/***********Spec ific Display******** ***/
} elseif ($chatray[2]!=NULL) {
switch ($chatray[3]) {
//Say To
case "say":
if ($chatray[1]!=$user AND $chatray[2]!=$user) {
//If the user is not posting or is not directed to....
$chatdisp=$chat disp.$chatray[1]." said to ".$chatray[2].", \"".$chatray[4]."\"<br>";
} elseif ($chatray[1]==$user AND $chatray[2]!=$user) {
//elseif the user is posting but is not directed to...
$chatdisp=$chat disp."<b>You said to ".$chatray[2].", \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user AND $chatray[2]==$user) {
//elseif the user is not posting but is being directed to...
$chatdisp=$chat disp."<b>".$cha tray[1]." said to you, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]==$user AND $chatray[2]==$user) {
//if the user posts to his or her self...
$chatdisp=$chat disp."<b>You said to yourself, \"".$chatray[4]."\"</b><br>";
}
break;
//Tell To
case "tell":
if ($chatray[1]!=$user AND $chatray[2]!=$user) {
$chatdisp=$chat disp;
} elseif ($chatray[1]==$user AND $chatray[2]!=$user) {
$chatdisp=$chat disp."<b>You told ".$chatray[2].", \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user AND $chatray[2]==$user) {
$chatdisp=$chat disp."<b>".$cha tray[1]." told you, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]==$user AND $chatray[2]==$user) {
$chatdisp=$chat disp."<b>You told yourself, \"".$chatray[4]."\"</b><br>";
}
break;
//Whisper To
case "whisper":
if ($chatray[1]!=$user AND $chatray[2]!=$user) {
$chatdisp=$chat disp.$chatray[1]." whispered something to ".$chatray[2].", but you can't hear what.<br>";
} elseif ($chatray[1]==$user AND $chatray[2]!=$user) {
$chatdisp=$chat disp."<b>You whispered to ".$chatray[2].", \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user AND $chatray[2]==$user) {
$chatdisp=$chat disp."<b>".$cha tray[1]." whispered to you, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]==$user AND $chatray[2]==$user) {
$chatdisp=$chat disp."<b>You whispered to yourself, \"".$chatray[4]."\"</b><br>";
}
break;
//Shout To
case "shout":
if ($chatray[1]!=$user AND $chatray[2]!=$user) {
$chatdisp=$chat disp.$chatray[1]." shouted to ".$chatray[2].", \"".$chatray[4]."\"<br>";
} elseif ($chatray[1]==$user AND $chatray[2]!=$user) {
$chatdisp=$chat disp."<b>You shouted to ".$chatray[2].", \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user AND $chatray[2]==$user) {
$chatdisp=$chat disp."<b>".$cha tray[1]." shouted to you, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]==$user AND $chatray[2]==$user) {
$chatdisp=$chat disp."<b>You shouted to yourself, \"".$chatray[4]."\"</b><br>";
}
break;
//Say OOCLY to
case "sayooc":
if ($chatray[1]!=$user AND $chatray[2]!=$user) {
$chatdisp=$chat disp.$chatray[1]." said OOCly to ".$chatray[2].", \"".$chatray[4]."\"<br>";
} elseif ($chatray[1]==$user AND $chatray[2]!=$user) {
$chatdisp=$chat disp."<b>You said OOCly to ".$chatray[2].", \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user AND $chatray[2]==$user) {
$chatdisp=$chat disp."<b>".$cha tray[1]." said OOCly to you, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]==$user AND $chatray[2]==$user) {
$chatdisp=$chat disp."<b>You said OOCly to yourself, \"".$chatray[4]."\"</b><br>";
}
break;
}
}
echo $chatdisp;
}
?>
[/php]
It's a lot of code, I know but most of it repeats. Anyway, a large explanation is needed to describe what my problem is.
Alright...
Basically, I've made a chat system in PHP and it works great and everything except for one thing... The $chatdisp doesn't clear at each page refresh (pages refresh on form submit, the messages are exploded and sent to the logs table which is then read out here). What happens is message 1 (any given command) is submitted while there are no other current posts to display so the echo looks like this:
Message 1
Alright, after command 1 has been submitted and is on the $chatdisp, what happens next is then you submit Message 2 and it ends up looking like this:
Message 1
Message 1
Message 2
And after a third message submitted...
Message 1
Message 1
Message 2
Message 1
Message 2
Message 3
As you can see, this would get really confusing really fast but to sum it up, my desired effect is this:
Message 1
Message 2
Message 3
And for my final issue, I want to make $chatdisp a $_SESSION[''] variable, if possible. Any and all help is GREATLY appreciated.
<?php
session_start() ;
/*CHAT DISPLAY*/
/*
Data for $chatray...
0 = id
1 = who
2 = towho
3 = type
4 = message
5 = when
6 = x
7 = y
8 = z
*/
$clear=$_SESSIO N['clear'];
$namechat="SELE CT * FROM `logs` WHERE `when`>='$clear ' AND `x`='$x' AND `y`='$y' AND `z`='$z' AND `month`='$month ' AND `day`='$day' AND `year`='$year'" ;
$querychat=mysq l_query($namech at);
while ($chatray=mysql _fetch_array($q uerychat)) {
/***********Stan dard Display******** ***/
if ($chatray[2]==NULL) {
switch ($chatray[3]) {
//Emote
case "/":
if ($chatray[1]==$user) {
//If the user is the one that posted...
$chatdisp=$chat disp."<b>You ".$chatray[4]."</b><br>";
} elseif ($chatray[1]!=$user) {
//elseif the user is not the one that posted...
$chatdisp=$chat disp.ucfirst($c hatray[1])." ".$chatray[4]."<br>";
}
break;
//Say
case "say":
if ($chatray[1]==$user) {
$chatdisp=$chat disp."<b>You said, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user) {
$chatdisp=$chat disp.ucfirst($c hatray[1])." said, \"".$chatray[4]."\"<br>";
}
break;
//Shout
case "shout":
if ($chatray[1]==$user) {
$chatdisp=$chat disp."<b>You shouted, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user) {
$chatdisp=$chat disp.ucfirst($c hatray[1])." shouted, \"".$chatray[4]."\"<br>";
}
break;
//Say OOCLY
case "sayooc":
if ($chatray[1]==$user) {
$chatdisp=$chat disp."<b>You said OOCly, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user) {
$chatdisp=$chat disp.ucfirst($c hatray[1])." said OOCly, \"".$chatray[4]."\"<br>";
}
break;
//OOC Emote
case "ooc":
if ($chatray[1]==$user) {
$chatdisp=$chat disp."<b>You OOCly ".$chatray[4]."</b><br>";
} elseif ($chatray[1]!=$user) {
$chatdisp=$chat disp.ucfirst($c hatray[1])." OOCly ".$chatray[4]."<br>";
}
break;
}
/***********Spec ific Display******** ***/
} elseif ($chatray[2]!=NULL) {
switch ($chatray[3]) {
//Say To
case "say":
if ($chatray[1]!=$user AND $chatray[2]!=$user) {
//If the user is not posting or is not directed to....
$chatdisp=$chat disp.$chatray[1]." said to ".$chatray[2].", \"".$chatray[4]."\"<br>";
} elseif ($chatray[1]==$user AND $chatray[2]!=$user) {
//elseif the user is posting but is not directed to...
$chatdisp=$chat disp."<b>You said to ".$chatray[2].", \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user AND $chatray[2]==$user) {
//elseif the user is not posting but is being directed to...
$chatdisp=$chat disp."<b>".$cha tray[1]." said to you, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]==$user AND $chatray[2]==$user) {
//if the user posts to his or her self...
$chatdisp=$chat disp."<b>You said to yourself, \"".$chatray[4]."\"</b><br>";
}
break;
//Tell To
case "tell":
if ($chatray[1]!=$user AND $chatray[2]!=$user) {
$chatdisp=$chat disp;
} elseif ($chatray[1]==$user AND $chatray[2]!=$user) {
$chatdisp=$chat disp."<b>You told ".$chatray[2].", \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user AND $chatray[2]==$user) {
$chatdisp=$chat disp."<b>".$cha tray[1]." told you, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]==$user AND $chatray[2]==$user) {
$chatdisp=$chat disp."<b>You told yourself, \"".$chatray[4]."\"</b><br>";
}
break;
//Whisper To
case "whisper":
if ($chatray[1]!=$user AND $chatray[2]!=$user) {
$chatdisp=$chat disp.$chatray[1]." whispered something to ".$chatray[2].", but you can't hear what.<br>";
} elseif ($chatray[1]==$user AND $chatray[2]!=$user) {
$chatdisp=$chat disp."<b>You whispered to ".$chatray[2].", \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user AND $chatray[2]==$user) {
$chatdisp=$chat disp."<b>".$cha tray[1]." whispered to you, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]==$user AND $chatray[2]==$user) {
$chatdisp=$chat disp."<b>You whispered to yourself, \"".$chatray[4]."\"</b><br>";
}
break;
//Shout To
case "shout":
if ($chatray[1]!=$user AND $chatray[2]!=$user) {
$chatdisp=$chat disp.$chatray[1]." shouted to ".$chatray[2].", \"".$chatray[4]."\"<br>";
} elseif ($chatray[1]==$user AND $chatray[2]!=$user) {
$chatdisp=$chat disp."<b>You shouted to ".$chatray[2].", \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user AND $chatray[2]==$user) {
$chatdisp=$chat disp."<b>".$cha tray[1]." shouted to you, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]==$user AND $chatray[2]==$user) {
$chatdisp=$chat disp."<b>You shouted to yourself, \"".$chatray[4]."\"</b><br>";
}
break;
//Say OOCLY to
case "sayooc":
if ($chatray[1]!=$user AND $chatray[2]!=$user) {
$chatdisp=$chat disp.$chatray[1]." said OOCly to ".$chatray[2].", \"".$chatray[4]."\"<br>";
} elseif ($chatray[1]==$user AND $chatray[2]!=$user) {
$chatdisp=$chat disp."<b>You said OOCly to ".$chatray[2].", \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user AND $chatray[2]==$user) {
$chatdisp=$chat disp."<b>".$cha tray[1]." said OOCly to you, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]==$user AND $chatray[2]==$user) {
$chatdisp=$chat disp."<b>You said OOCly to yourself, \"".$chatray[4]."\"</b><br>";
}
break;
}
}
echo $chatdisp;
}
?>
[/php]
It's a lot of code, I know but most of it repeats. Anyway, a large explanation is needed to describe what my problem is.
Alright...
Basically, I've made a chat system in PHP and it works great and everything except for one thing... The $chatdisp doesn't clear at each page refresh (pages refresh on form submit, the messages are exploded and sent to the logs table which is then read out here). What happens is message 1 (any given command) is submitted while there are no other current posts to display so the echo looks like this:
Message 1
Alright, after command 1 has been submitted and is on the $chatdisp, what happens next is then you submit Message 2 and it ends up looking like this:
Message 1
Message 1
Message 2
And after a third message submitted...
Message 1
Message 1
Message 2
Message 1
Message 2
Message 3
As you can see, this would get really confusing really fast but to sum it up, my desired effect is this:
Message 1
Message 2
Message 3
And for my final issue, I want to make $chatdisp a $_SESSION[''] variable, if possible. Any and all help is GREATLY appreciated.
Comment