IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

Système de notification en temps réel


Sujet :

PHP & Base de données

  1. #1
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2011
    Messages
    69
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Décembre 2011
    Messages : 69
    Points : 98
    Points
    98
    Par défaut Système de notification en temps réel
    Je suis en train d'essayer de créer un système de notification en temps réel pour le site social que je suis en train de développer en utilisant Symfony2. J'ai réussi d'exécuter le système de notification mais le problème est qu'il ne marche pas correctement. L'explication est ci-dessous:

    J'ai téléchargé le calendrier wdCalendar depuis ce lien : http://www.webappers.com/2010/06/08/...alendar-clone/ (Vous pouvez voir le démo sur ce lien: http://www.web-delicious.com/jquery-...dar/sample.php ) et j'ai l'intégré en Symfony2. Puis j'ai crée trois fichiers: mapage.html , moslem.php and moslem1.php. Le code de chacun d'eux est ci-dessous:

    Le code de mapage.html:
    Code javascript : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    $(document).ready(function() {
            setTimeout( test, 1000);   
    });
        function test() {
            var start = new Date().getMilliseconds();
            $.ajax({
                url: 'moslem.php',
                type: 'POST',
                success: function(data) {
                    var max;
                    max = data;
                    function test1() {
                        $.ajax({
                            url: 'moslem1.php',
                            type: 'POST',
                            dataType: 'JSON',
                            success: function(data1) {
                                if(data1.id>max)
                                {
                                    document.write("an event was added with the id: "+data1.id+" and with the subject: "+data1.subject+"<br>");
                                }
                            }
                        });
                    }
                    var end = new Date().getMilliseconds();
                    var time = end - start;
                    var time1 = 1000 - time;
                    setTimeout( test1, time1);
        }
            });
            setTimeout( test, 1000);   
    }

    Le code de moslem.php :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    <?php
    $con=mysqli_connect("localhost","root","","test");
    if (mysqli_connect_errno()) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    $result = mysqli_query($con,"SELECT * FROM jqcalendar ORDER BY id DESC LIMIT 0, 1");
    $num_rows = mysqli_num_rows($result);
    if($num_rows!=0){
    while($row = mysqli_fetch_array($result)) {
        $max=$row['Id'];
    }
    echo $max;
    }
    mysqli_close($con);
    ?>
    le code de moslem1.php :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    <?php
    $con=mysqli_connect("localhost","root","","test");
    if (mysqli_connect_errno()) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    $result = mysqli_query($con,"SELECT * FROM jqcalendar ORDER BY id DESC LIMIT 0, 1");
    while($row = mysqli_fetch_array($result)) {
        $notification = array('id'=>$row['Id'],'subject'=>$row['Subject'],'location'=>$row['Location'],'description'=>$row['Description'],'starttime'=>$row['StartTime'],'endtime'=>$row['EndTime']);
    }
    echo json_encode($notification);
    mysqli_close($con);
    ?>
    Dans la base de données sur laquelle je travaille il y a une table appelée "jqcalendar" dont la structure est comme suit:

    Id : int(11)
    Subject : varchar(1000)
    Location : varchar(200)
    Description : varchar(255)
    StartTime : datetime
    EndTime : datetime
    IsAllDayEvent : smallint(6)
    Color : varchar(200)
    RecurringRule : varchar(500)
    Le champs "Id" ci-dessus est l'identifiant primaire de la table "jqcalendar" et il est auto-incrément. Concernant le principe du système de notification que je suis en train d'essayé de créer est comme suit: lorsque un événement est ajouté dans le calendrier, une insertion d'une nouvelle ligne dans la table "jqcalendar" aura lieu et elle sera détectée grâce à une requête jquery/Ajax (sur la table "jqcalendar") qui se passe chaque seconde. Puis, le contenu de quelques champs (ici dans notre exemple, ce sont les deux champs "Id" et "Subject") va être affiché sur l’écran (en fait, le fichier mapage.html c'est celui que se charge par cet affichage là) comme étant une notification. En fait, le problème est que j'ajoute un événement avec l'identifiant ayant une valeur de 10 ou bien les multiples de 10 (par exemple: 100, 1000, 10000,...etc) la notification ne sera pas affichée. Au fait, j'ai ajouté 20 événements dans le calendrier et voilà c'est ce que j'ai obtenu comme affichage sur l'écran:

    an event was added with the id: 1 and with the subject: a
    an event was added with the id: 2 and with the subject: z
    an event was added with the id: 3 and with the subject: e
    an event was added with the id: 4 and with the subject: r
    an event was added with the id: 5 and with the subject: t
    an event was added with the id: 6 and with the subject: y
    an event was added with the id: 7 and with the subject: u
    an event was added with the id: 8 and with the subject: i
    an event was added with the id: 9 and with the subject: o
    an event was added with the id: 11 and with the subject: m
    an event was added with the id: 12 and with the subject: q
    an event was added with the id: 13 and with the subject: s
    an event was added with the id: 14 and with the subject: d
    an event was added with the id: 15 and with the subject: f
    an event was added with the id: 16 and with the subject: g
    an event was added with the id: 17 and with the subject: h
    an event was added with the id: 18 and with the subject: j
    an event was added with the id: 19 and with the subject: k
    an event was added with the id: 20 and with the subject: l
    Comme vous pouvez le remarquer bien ci-dessus, il y a une notification manquante qui est celle de l'événement ayant l'identifiant est égal à 10. Veuillez juste se concentrer sur ces deux lignes:

    an event was added with the id: 9 and with the subject: o
    an event was added with the id: 11 and with the subject: m
    Alors, ma question est comment je peux résoudre ce problème là??..Vraiment moi je m'étonne pourquoi on m'affiche pas les notifications relatives aux événements avec des identifiants ayant comme des valeurs 10 ou bien multiples de 10 exactement?? ( comme j'ai dit soit 100 ou bien 1000 ou bien 10000 ....etc). j'ai vraiment essayé depuis un longtemps mais malheureusement jusqu'au maintenant j'ai pas arrivé à trouvé la solution..Est ce qu'il y a quelqu'un qui peut m'aider???

    Merci d'avance.

  2. #2
    Membre actif Avatar de zaza576
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Août 2013
    Messages
    175
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Août 2013
    Messages : 175
    Points : 275
    Points
    275
    Par défaut
    Bonjour,

    peux-tu nous donner la valeur de data1.id et max quand tu passes la condition if(data1.id>max) pour id = 10 ?

    Peux-tu vérifier que dans ta base de données, le tuple contenant l'id = 10 existe bien ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    function googleIsYourF*ck*ngFriend(String url, String maQuestion){
        goTo(url);
        reponse = find(maQuestion);
        if(isAcceptable(reponse)){
            clickOn(By.xpath("//button[@id='resolvedButton']"));
        }
        sendMessage("Merci");
    }
    
    googleIsYourF*ck*ingFriend("http://www.google.fr", "ma question");

Discussions similaires

  1. Réponses: 2
    Dernier message: 08/05/2014, 10h54
  2. [Débutant] notification en temps réel d'insertion linq to sql, c#
    Par zikog dans le forum C#
    Réponses: 3
    Dernier message: 14/09/2011, 10h58
  3. Notifications en temps réel (gmail like)
    Par muad'dib dans le forum ALM
    Réponses: 2
    Dernier message: 16/05/2011, 14h04
  4. Réponses: 0
    Dernier message: 22/11/2010, 10h59
  5. Réponses: 2
    Dernier message: 26/08/2007, 12h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo