Added instant message feature.
[Assignment-Trapper.git] / im_chat_update.php
blob389cb12558c03158015ea6e9ba6f27a49817e200
1 <?php
2 include_once("auth.php");
3 //sleep(1);
4 $_GET["user"] = mysql_real_escape_string($_GET["user"]);
5 if($_GET["id"] == -1) {
6 $sql = "select chat_id, time(chat_time) as short_chat_time, name, content from chat, users where users.user_id = chat.user_id and chat_time > NOW() - interval 5 minute";
7 } else {
8 $sql = "select chat_id, time(chat_time) as short_chat_time, name, content from chat, users where users.user_id = chat.user_id and chat_id > ".$_GET["id"]." limit 100";
10 $result = mysql_query($sql);
11 $chat_data = '{"m":[';
12 if(mysql_num_rows($result)){
13 while($row = mysql_fetch_array($result)){
14 $chat_data .= '{"id": '.$row[chat_id].',"t":"'.$row[short_chat_time].'","n":"'.$row[name].'","c":"'.$row[content].'"},';
16 $chat_data = substr($chat_data, 0, -1);
17 $chat_data .= ']}';
18 } else $chat_data .= "]}";
19 echo $chat_data;