Chat problem

Hi, I'm implementing a chat I found on the web (opensource), but I've made some changes. Mainly in the frame where the messages are shown but now no messages show at all. I've checked the code lots of times and cant figure out what's the problem. If anyone sees the problem please help me. Thanks.


[code]
$query = "UPDATE users SET active = 'y', sent_on = DATE_ADD(NOW(), INTERVAL $diff_timezone HOUR) WHERE username = '$username'";
do_the_query($chat_db, $query);

$q = "SELECT * FROM users WHERE username='$username'";
$r = do_the_query($chat_db, $q);

/* delete old messages from our db */
$sent_on = date("YmdHis", time() - 60 * 60 * 24); /* 24 hours ago */
$query = "DELETE FROM msg WHERE sent_on < '$sent_on'";
do_the_query($chat_db, $query);

echo "";
echo "
";
echo "
";
echo "

";

echo "";
//echo "
";
while($r["active"] == 'y'){
$query = "SELECT username, color, msg, HOUR(sent_on) AS hour, MINUTE(sent_on) AS minutes, SECOND(sent_on) AS seconds FROM msg ORDER BY sent_on desc LIMIT 1";
$result = do_the_query($chat_db, $query);
$row = mysql_fetch_array($result);

switch ($row["color"]) {
case "1":
$colore = $lightgreen; /* lightgreen */
break;
case "2":
$colore = $yellow; /* yellow */
break;
case "3":
$colore = $red; /* red */
break;
case "4":
$colore = $green;/* green */
break;
case "5":
$colore = $blue; /* blue */
break;
case "6":
$colore = $brown;/* brown */
break;
case "7":
$colore = $violet;/* violet */
break;
case "8":
$colore = $darkyellow; /* light red */
break;
case "9":
$colore = $black;/* black */
break;
default:
$colore = $black; /* Black (by default) */
break;
}
$hour = ($row["hour"] < 10 ? "0" . $row["hour"] : $row["hour"]);
$minutes = ($row["minutes"] < 10 ? "0" . $row["minutes"] : $row["minutes"]);
$seconds = ($row["seconds"] < 10 ? "0" . $row["seconds"] : $row["seconds"]);

/* which kind of message is this? */
if ($row["username"] == "") {
echo "[" . stripslashes($row["msg"]) . " entrou no chat - $hour:$minutes:$seconds]

";
}
else {
echo "($hour:$minutes:$seconds)
";
echo "[" . stripslashes($row["username"]) . "] : " . stripslashes($row["msg"]) . "

";
}


mysql_free_result($result);

/* this user is active: save it! */
$query = "UPDATE users SET active = 'y', sent_on = DATE_ADD(NOW(), INTERVAL $diff_timezone HOUR) WHERE username = '$username'";
do_the_query($chat_db, $query);
$r = do_the_query($chat_db, $q);
}
//echo "
";
echo "";
echo "
";
[/code]

Comments

  • I could be wrong but your delete query looks a little funky. Check to make sure there is actually chat messages to be displayed in your DB.

    T

    : Hi, I'm implementing a chat I found on the web (opensource), but I've made some changes. Mainly in the frame where the messages are shown but now no messages show at all. I've checked the code lots of times and cant figure out what's the problem. If anyone sees the problem please help me. Thanks.
    :
    :
    : [code]
    : $query = "UPDATE users SET active = 'y', sent_on = DATE_ADD(NOW(), INTERVAL $diff_timezone HOUR) WHERE username = '$username'";
    : do_the_query($chat_db, $query);
    :
    : $q = "SELECT * FROM users WHERE username='$username'";
    : $r = do_the_query($chat_db, $q);
    :
    : /* delete old messages from our db */
    : $sent_on = date("YmdHis", time() - 60 * 60 * 24); /* 24 hours ago */
    : $query = "DELETE FROM msg WHERE sent_on < '$sent_on'";
    : do_the_query($chat_db, $query);
    :
    : echo "";
    : echo "
    ";
    : echo "
    ";
    : echo "

    ";
    :
    : echo "";
    : //echo "
    ";
    : while($r["active"] == 'y'){
    : $query = "SELECT username, color, msg, HOUR(sent_on) AS hour, MINUTE(sent_on) AS minutes, SECOND(sent_on) AS seconds FROM msg ORDER BY sent_on desc LIMIT 1";
    : $result = do_the_query($chat_db, $query);
    : $row = mysql_fetch_array($result);
    :
    : switch ($row["color"]) {
    : case "1":
    : $colore = $lightgreen; /* lightgreen */
    : break;
    : case "2":
    : $colore = $yellow; /* yellow */
    : break;
    : case "3":
    : $colore = $red; /* red */
    : break;
    : case "4":
    : $colore = $green;/* green */
    : break;
    : case "5":
    : $colore = $blue; /* blue */
    : break;
    : case "6":
    : $colore = $brown;/* brown */
    : break;
    : case "7":
    : $colore = $violet;/* violet */
    : break;
    : case "8":
    : $colore = $darkyellow; /* light red */
    : break;
    : case "9":
    : $colore = $black;/* black */
    : break;
    : default:
    : $colore = $black; /* Black (by default) */
    : break;
    : }
    : $hour = ($row["hour"] < 10 ? "0" . $row["hour"] : $row["hour"]);
    : $minutes = ($row["minutes"] < 10 ? "0" . $row["minutes"] : $row["minutes"]);
    : $seconds = ($row["seconds"] < 10 ? "0" . $row["seconds"] : $row["seconds"]);
    :
    : /* which kind of message is this? */
    : if ($row["username"] == "") {
    : echo "[" . stripslashes($row["msg"]) . " entrou no chat - $hour:$minutes:$seconds]
    ";
    : }
    : else {
    : echo "($hour:$minutes:$seconds)
    ";
    : echo "[" . stripslashes($row["username"]) . "] : " . stripslashes($row["msg"]) . "
    ";
    : }
    :
    :
    : mysql_free_result($result);
    :
    : /* this user is active: save it! */
    : $query = "UPDATE users SET active = 'y', sent_on = DATE_ADD(NOW(), INTERVAL $diff_timezone HOUR) WHERE username = '$username'";
    : do_the_query($chat_db, $query);
    : $r = do_the_query($chat_db, $q);
    : }
    : //echo "
    ";
    : echo "";
    : echo "
    ";
    : [/code]
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion