473,473 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Repeating old data in a while statement

The1corrupted
134 New Member
[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=$_SESSION['clear'];
$namechat="SELECT * FROM `logs` WHERE `when`>='$clear' AND `x`='$x' AND `y`='$y' AND `z`='$z' AND `month`='$month' AND `day`='$day' AND `year`='$year'";
$querychat=mysql_query($namechat);

while ($chatray=mysql_fetch_array($querychat)) {
/***********Standard Display***********/
if ($chatray[2]==NULL) {
switch ($chatray[3]) {
//Emote
case "/":
if ($chatray[1]==$user) {
//If the user is the one that posted...
$chatdisp=$chatdisp."<b>You ".$chatray[4]."</b><br>";
} elseif ($chatray[1]!=$user) {
//elseif the user is not the one that posted...
$chatdisp=$chatdisp.ucfirst($chatray[1])." ".$chatray[4]."<br>";
}
break;
//Say
case "say":
if ($chatray[1]==$user) {
$chatdisp=$chatdisp."<b>You said, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user) {
$chatdisp=$chatdisp.ucfirst($chatray[1])." said, \"".$chatray[4]."\"<br>";
}
break;
//Shout
case "shout":
if ($chatray[1]==$user) {
$chatdisp=$chatdisp."<b>You shouted, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user) {
$chatdisp=$chatdisp.ucfirst($chatray[1])." shouted, \"".$chatray[4]."\"<br>";
}
break;
//Say OOCLY
case "sayooc":
if ($chatray[1]==$user) {
$chatdisp=$chatdisp."<b>You said OOCly, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user) {
$chatdisp=$chatdisp.ucfirst($chatray[1])." said OOCly, \"".$chatray[4]."\"<br>";
}
break;
//OOC Emote
case "ooc":
if ($chatray[1]==$user) {
$chatdisp=$chatdisp."<b>You OOCly ".$chatray[4]."</b><br>";
} elseif ($chatray[1]!=$user) {
$chatdisp=$chatdisp.ucfirst($chatray[1])." OOCly ".$chatray[4]."<br>";
}
break;
}
/***********Specific 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=$chatdisp.$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=$chatdisp."<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=$chatdisp."<b>".$chatray[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=$chatdisp."<b>You said to yourself, \"".$chatray[4]."\"</b><br>";
}
break;
//Tell To
case "tell":
if ($chatray[1]!=$user AND $chatray[2]!=$user) {
$chatdisp=$chatdisp;
} elseif ($chatray[1]==$user AND $chatray[2]!=$user) {
$chatdisp=$chatdisp."<b>You told ".$chatray[2].", \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user AND $chatray[2]==$user) {
$chatdisp=$chatdisp."<b>".$chatray[1]." told you, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]==$user AND $chatray[2]==$user) {
$chatdisp=$chatdisp."<b>You told yourself, \"".$chatray[4]."\"</b><br>";
}
break;
//Whisper To
case "whisper":
if ($chatray[1]!=$user AND $chatray[2]!=$user) {
$chatdisp=$chatdisp.$chatray[1]." whispered something to ".$chatray[2].", but you can't hear what.<br>";
} elseif ($chatray[1]==$user AND $chatray[2]!=$user) {
$chatdisp=$chatdisp."<b>You whispered to ".$chatray[2].", \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user AND $chatray[2]==$user) {
$chatdisp=$chatdisp."<b>".$chatray[1]." whispered to you, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]==$user AND $chatray[2]==$user) {
$chatdisp=$chatdisp."<b>You whispered to yourself, \"".$chatray[4]."\"</b><br>";
}
break;
//Shout To
case "shout":
if ($chatray[1]!=$user AND $chatray[2]!=$user) {
$chatdisp=$chatdisp.$chatray[1]." shouted to ".$chatray[2].", \"".$chatray[4]."\"<br>";
} elseif ($chatray[1]==$user AND $chatray[2]!=$user) {
$chatdisp=$chatdisp."<b>You shouted to ".$chatray[2].", \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user AND $chatray[2]==$user) {
$chatdisp=$chatdisp."<b>".$chatray[1]." shouted to you, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]==$user AND $chatray[2]==$user) {
$chatdisp=$chatdisp."<b>You shouted to yourself, \"".$chatray[4]."\"</b><br>";
}
break;
//Say OOCLY to
case "sayooc":
if ($chatray[1]!=$user AND $chatray[2]!=$user) {
$chatdisp=$chatdisp.$chatray[1]." said OOCly to ".$chatray[2].", \"".$chatray[4]."\"<br>";
} elseif ($chatray[1]==$user AND $chatray[2]!=$user) {
$chatdisp=$chatdisp."<b>You said OOCly to ".$chatray[2].", \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]!=$user AND $chatray[2]==$user) {
$chatdisp=$chatdisp."<b>".$chatray[1]." said OOCly to you, \"".$chatray[4]."\"</b><br>";
} elseif ($chatray[1]==$user AND $chatray[2]==$user) {
$chatdisp=$chatdisp."<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.
Apr 1 '07 #1
1 1234
The1corrupted
134 New Member
Can I get any help at all?
Apr 29 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Wescotte | last post by:
Here is a small sample program I wrote in PHP (running off Apache 1.3.31 w/ PHP 5.0.1) to help illustrates problem I'm having. The data base is using DB2 V5R3M0. The client is WinXP machine using...
9
by: Wescotte | last post by:
Here is a small sample program I wrote in PHP to help illustrates problem I'm having. The data base is using DB2 V5R3M0. The client is WinXP machine using the iSeries Client Access Driver ver...
0
by: Wescotte | last post by:
Here is a small sample program I wrote in PHP to help illustrates problem I'm having. The data base is using DB2 V5R3M0. The client is WinXP machine using the iSeries Client Access Driver ver...
5
by: Tom Lam lemontea | last post by:
Hi all, This is my very first post here, I've seriously tried some programming on C, and shown below is my very first program(So you can expect it to be very messy) that I wrote after I've learned...
2
by: nickheppleston | last post by:
I'm trying to iterate through repeating elements to extract data using libxml2 but I'm having zero luck - any help would be appreciated. My XML source is similar to the following - I'm trying to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.