Hallo One2xsers,
Ik en mn partner zitten weer es met een hersenkrakend probleem. Misschien zijn hier personen die ervaren zijn met Javascript?
Wat heb ik al voor mekaar:
- tijd en tijd later in een database
- een javascriptfunctie die het tijdsverschil laat aftellen
Wat wil ik voor mekaar krijgen:
In de game moeten mensen oneindig aanvallen kunnen doen, en ik wil de tijden laten zien hoelang de aanvallen nog duren. Ik moet dus alle vars(steeds dezelfde per aanval) door kunnen sturen naar een javascriptfunctie(die ik al heb) en die javascriptfunctie die moet mij dan in een div de tijden laten zien.
Ik heb alleen geen flauw idee hoe ik dit voor mekaar moet krijgen, hier een stukje code wat perfect werkt en wat ik had:
Deze code haalt dus 1 malig tijden op en haalt uren, minuten seconden los van mekaar... berekend het verschil en laat het aftellen. Wie me een goeie duw in de richting kan geven hoe ik die voor oneindige waardes voor mekaar kan krijgen ben ik eeuwig dankbaar.
~tgrm
Ik en mn partner zitten weer es met een hersenkrakend probleem. Misschien zijn hier personen die ervaren zijn met Javascript?
Wat heb ik al voor mekaar:
- tijd en tijd later in een database
- een javascriptfunctie die het tijdsverschil laat aftellen
Wat wil ik voor mekaar krijgen:
In de game moeten mensen oneindig aanvallen kunnen doen, en ik wil de tijden laten zien hoelang de aanvallen nog duren. Ik moet dus alle vars(steeds dezelfde per aanval) door kunnen sturen naar een javascriptfunctie(die ik al heb) en die javascriptfunctie die moet mij dan in een div de tijden laten zien.
Ik heb alleen geen flauw idee hoe ik dit voor mekaar moet krijgen, hier een stukje code wat perfect werkt en wat ik had:
[COLOR= #0000BB]<?php
$gettimes[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM ..... WHERE ..... = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000].....[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$rowtimes[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$gettimes[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$targetYear[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/substr"]substr[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$rowtimes[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000].....[/COLOR][COLOR= #007700]],[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]4[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$targetMonth[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/substr"]substr[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$rowtimes[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000].....[/COLOR][COLOR= #007700]],[/COLOR][COLOR= #0000BB]5[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$targetDay[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/substr"]substr[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$rowtimes[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000].....[/COLOR][COLOR= #007700]],[/COLOR][COLOR= #0000BB]8[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$targetHour[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/substr"]substr[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$rowtimes[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000].....[/COLOR][COLOR= #007700]],[/COLOR][COLOR= #0000BB]11[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$targetMinute[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/substr"]substr[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$rowtimes[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000].....[/COLOR][COLOR= #007700]],[/COLOR][COLOR= #0000BB]14[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$targetSecond[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/substr"]substr[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$rowtimes[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000].....[/COLOR][COLOR= #007700]],[/COLOR][COLOR= #0000BB]17[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$dateFormat[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"Y-m-d H:i:s"[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$targetDate[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mktime"]mktime[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$targetHour[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$targetMinute[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$targetSecond[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$targetMonth[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$targetDay[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$targetYear[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$actualDate[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/time"]time[/URL][COLOR= #007700]();[/COLOR]
[COLOR= #0000BB]$secondsDiff[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$targetDate[/COLOR] [COLOR= #007700]-[/COLOR] [COLOR= #0000BB]$actualDate[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$remainingDay[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/floor"]floor[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$secondsDiff[/COLOR]/[COLOR= #0000BB]60[/COLOR]/[COLOR= #0000BB]60[/COLOR]/[COLOR= #0000BB]24[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$remainingHour[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/floor"]floor[/URL][COLOR= #007700](([/COLOR][COLOR= #0000BB]$secondsDiff[/COLOR][COLOR= #007700]-([/COLOR][COLOR= #0000BB]$remainingDay[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]60[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]60[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]24[/COLOR][COLOR= #007700]))[/COLOR]/[COLOR= #0000BB]60[/COLOR]/[COLOR= #0000BB]60[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$remainingMinutes[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/floor"]floor[/URL][COLOR= #007700](([/COLOR][COLOR= #0000BB]$secondsDiff[/COLOR][COLOR= #007700]-([/COLOR][COLOR= #0000BB]$remainingDay[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]60[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]60[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]24[/COLOR][COLOR= #007700])-([/COLOR][COLOR= #0000BB]$remainingHour[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]60[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]60[/COLOR][COLOR= #007700]))[/COLOR]/[COLOR= #0000BB]60[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$remainingSeconds[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/floor"]floor[/URL][COLOR= #007700](([/COLOR][COLOR= #0000BB]$secondsDiff[/COLOR][COLOR= #007700]-([/COLOR][COLOR= #0000BB]$remainingDay[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]60[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]60[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]24[/COLOR][COLOR= #007700])-([/COLOR][COLOR= #0000BB]$remainingHour[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]60[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]60[/COLOR][COLOR= #007700]))-([/COLOR][COLOR= #0000BB]$remainingMinutes[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]60[/COLOR][COLOR= #007700]));[/COLOR]
[COLOR= #0000BB]$targetDateDisplay[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/date"]date[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$dateFormat[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$targetDate[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$actualDateDisplay[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/date"]date[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$dateFormat[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$actualDate[/COLOR][COLOR= #007700]);[/COLOR]
?>
<script type="text/javascript">
var days = [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$remainingDay[/COLOR][COLOR= #007700];[/COLOR] ?>
var hours = [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$remainingHour[/COLOR][COLOR= #007700];[/COLOR] ?>
var minutes = [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$remainingMinutes[/COLOR][COLOR= #007700];[/COLOR] ?>
var seconds = [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$remainingSeconds[/COLOR][COLOR= #007700];[/COLOR] ?>
function setCountDown ()
{
if(seconds == 0 && minutes == 0 && hours == 0){
}
else{
seconds--;
}
if (seconds < 0){
minutes--;
seconds = 59
}
if (minutes < 0){
hours--;
minutes = 59
}
if (hours < 0){
days--;
hours = 23
}
document.getElementById("remain").innerHTML = "Je moet nog "+hours+":"+minutes+":"+seconds+" wachten.";
setTimeout ( "setCountDown()", 1000 );
}
</script> Deze code haalt dus 1 malig tijden op en haalt uren, minuten seconden los van mekaar... berekend het verschil en laat het aftellen. Wie me een goeie duw in de richting kan geven hoe ik die voor oneindige waardes voor mekaar kan krijgen ben ik eeuwig dankbaar.

~tgrm