'$stamp' and room='$room' order by timestamp ASC"; $result = @mysql_query($sql); $row = @mysql_num_rows($result); while ($row == 0) { usleep(10000); // sleep 10ms to unload the CPU $result = @mysql_query($sql); $row = @mysql_num_rows($result); } // return a json array $response = array(); $row = mysql_fetch_row($result); //{ $response['msg'] = $row[4]; $response['user'] = $row[2]; $response['timestamp'] = $row[3]; $response['stamp'] = $row[5]; echo json_encode($response); flush(); //} ?>