1

I need help because my script does not work as I would like

Basically, I create a loop that if "$temporairesoldat> 0" runs a counter of 240second and at the end of this counter increments +1 in the "soldat" table and -1 in the "temporairesoldat" table and when "$temporairesoldat <= 0 "is over.

<script>
var compte = 240;
function decompte()
{
    if(compte <= 1) {
        pluriel = "";
    } else {
        pluriel = "s";
    }

    document.getElementById("compt").innerHTML = compte + " seconde" + pluriel;

    if(compte == 0 || compte < 0) {
        compte = 0;
        '<?php $bdd->prepare(" UPDATE caserne SET soldat=soldat+1, temporairesoldat=temporairesoldat-1 "); ?>'
        clearInterval(timer);
    }

    compte--;
}
var timer = setInterval('decompte()',1000);
</script>

<span id="compt"></span>
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Chrys
  • 79
  • 1
  • 8
  • 1
    why cant you make an ajax call to your php script and then perform your SQL operation? this is really bad practice – Rotimi Apr 10 '17 at 07:42
  • Possible duplicate of [What is the difference between client-side and server-side programming?](http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – M. Eriksson Apr 10 '17 at 07:42
  • @Akin Its not only bad practice, its worse, because it won't work at all. You can't mix up javascript and PHP this way. Take a look at the link Magnus provided and learn about the difference btween server - & clientside. You'll see that this code won't work at all. An AJAX call would be the right solution. – Twinfriends Apr 10 '17 at 07:48
  • ok ajax it's the solution ty :) – Chrys Apr 10 '17 at 07:51

0 Answers0