2012-05-06 7 views
0

どうすればを選ぶのユーザーの新しい通知を受け取りますか?私はここにすべてのユーザー通知phpとajaxのnotifcations

//PHP PART 
    "SELECT * 
    FROM notifications 
    WHERE tagged_by = "12042905" and action = \"unread\""; 

    //JAVASCRIPT PART 
    function n() { 
     $.ajax({ 
      url: "notifications.php", 
      dataType: "json", 
      success: function(responseJSON) { 
      $("div").html(reponseJSON[0].notify_id) 
      } 
     }) 
    } 

    setInterval("n()", 1000) 

を取得するコードを持っている。しかし、それは私のすべての通知毎秒を与える enter image description here

通知テーブル。今私の問題は、通知テーブルで新しく追加された行だけを取得したいのです。どのようにすればよいのですか?一度に1つずつ出力する方法はありますか? jQueryで.append()または.insert()を使用する必要がありますか?

注:date_notify構文Y-M-Dの時間である:I:Sまたは "2012-05-06午後05時11分18秒"

答えて

0

あなたは単にあなたのMySQLのクエリに制限を追加することができます。

"SELECT * 
FROM notifications 
WHERE tagged_by = "12042905" and action = \"unread\" 
LIMIT 1"; 
0

あなたの問題は、通知を送信した後、「未読」から「読み取り」に「アクション」の値を更新していないことです。
解決方法は簡単です。プル(選択クエリ)ごとに、選択したすべての行を更新する必要があります。

また、 'action'列の場合、データベースを最適化するために未読と読み込みの代わりに0と1の値を使用する必要があります。

0
Your problem is, you have a timer that keep on calling your function n() every 1sec at a time 
    so the output will repeat until timer keep on running. , so to avoid that problem? 

    1. The "Div" handler that will hold your ouput will empty first! 
    ex. 
     $("div").empty(); 
    2. try to use append() 

    ex. $("div").append(reponseJSON[0].notify_id); 

    Hope this will help! tnx