Chat window now opens with no messages inside.
[Assignment-Trapper.git] / im_chat_update.php
blobe3486a6a9f4f7004fc854fe1d29b40f341978dea
1 <?php
2 include_once("auth.php");
3 //sleep(1);
4 if(isset($_GET["user"])) { $_GET["user"] = mysql_real_escape_string($_GET["user"]); }
5 if($_GET["id"] == -1) { // first time to requst data - send highest message id
6 $sql = "select max(chat_id) from chat";
7 $result = mysql_query($sql);
8 $row = mysql_fetch_array($result);
9 echo '{"m":[{"id":'.$row[0]."}]}";
10 } else {
11 $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 20";
12 $result = mysql_query($sql);
13 $chat_data = '{"m":[';
14 if(mysql_num_rows($result)){
15 while($row = mysql_fetch_array($result)){
16 $chat_data .= '{"id": '.$row[chat_id].',"t":"'.$row[short_chat_time].'","n":"'.$row[name].'","c":"'.$row[content].'"},';
18 $chat_data = substr($chat_data, 0, -1);
19 $chat_data .= ']}';
20 } else $chat_data .= "]}";
21 echo $chat_data;