If you want to use one db query and wait for response here is how it can be made:

//js part
function getMessage(user_id){
$.ajax({
url: ‘process.php’,
data: {id: user_id},
type: ‘GET’,
success: function(data){
//your data goes here;
getMessage(user_id) // execute function again;
}
});
}
//php part
while (true) {
$sql = mysql_query(“SELECT * FROM messages WHERE id = ‘$id’ AND view = ’0′ ORDER BY date_added ASC”);
if(mysql_num_rows($sql) != 0){
while($row= mysql_fetch_array($sql)){
$message = $row['text'];
echo $message;
}
die();
}
flush();
sleep(5);
}

So , here we have infinite loop , and we are waiting for new message for our user.

flush() clears the cached data;

sleep(seconds) give a break for the server (wait x seconds before loop again);

Simple as that ;)