2 include_once("auth.php");
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]."}]}";
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);
20 } else $chat_data .= "]}";