add with php loop push

Asked

Viewed 111 times

0

have this result the result should be 125 150 175 ... and the result that I always have the same value Code follows server class

<?php

require_once ('configurations/config.php');

// arquivo cujo conteúdo será enviado ao cliente

//$dataFileName = 'data.txt';


$timestart=time();
$PDO = new PDO('mysql:host=localhost;dbname=game', 'root','');

if(isset($_POST ['timestamp'])){

    $timestamp=$_POST [ 'timestamp' ];

}
else {
    $tempo=$PDO->prepare("SELECT NOW() as now");
    $tempo->execute();
    $row=$tempo->fetchObject();
    $timestamp=$row->now;
}
/* $sql = $PDO->prepare( "SELECT * FROM comments WHERE timestamp >'$timestamp'" );

 $newdata = false;
 $notificacoes=array();
 while (!$newdata &&(time()-$timestart)<20) {
     $sql->execute();
 while ($row=$sql->fetchAll(PDO::FETCH_ASSOC)) {

     $notificacoes=$row;
        $newdata=true;
 }  
 usleep(500000);  
 } 
 $tempo=$PDO->prepare("SELECT NOW() as now");
    $tempo->execute();
    $row=$tempo->fetchObject();
    $timestamp=$row->now;
    $data= array('notificacoes'=>$notificacoes,'timestamp'=>$timestamp);
    echo json_encode($data);
    exit();

*/
$sql = $PDO->prepare("SELECT cidade.ouro,cidade.madeira,cidade.metal,cidade.pedra,cidade.energia, cidade.comida,cidade.petrolio FROM users INNER JOIN cidade ON users.cod_user=cidade.cod_user WHERE cidade.timestamp>'$timestamp'AND users.username='admin';");

 $newdata = false;
 $notificacoes=array();
 while (!$newdata &&(time()-$timestart)<20) {
     $sql->execute();
 while ($row=$sql->fetchAll(PDO::FETCH_ASSOC)) {

     $notificacoes=$row;
        $newdata=true;
 }  
 usleep(500000);  
 } 
 $tempo=$PDO->prepare("SELECT NOW() as now");
    $tempo->execute();
    $row=$tempo->fetchObject();
    $timestamp=$row->now;
    $data= array('notificacoes'=>$notificacoes,'timestamp'=>$timestamp);
    echo json_encode($data);
    exit();
?>

clients.js

$(function(){
notificacoes();
});
function notificacoes(timestamp){
    var data={};
    var resultado=0;
            var soma=2;
            var valor=25;
    if(typeof timestamp!='undefined')
    data.timestamp=timestamp;
    $.post('server.php',data,function(res){
        for(i in res.notificacoes ){

            resultado=+res.notificacoes[i].ouro+valor;

            $('#response').append(resultado);
        }

        notificacoes(res.timestamp);
    },'json');

}

someone can tell me where is the problem

  • what is the result of res.notificacoes ? (post)

  • this -me to give [Object Object] the code where I call the <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script type="text/javascript" src="dist/js/client.js"></script> </head> <body> <H3> <div id="Response" name="Response"></div> </body> </html>

  • topical can be closed already solved the problem

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.