Countdown

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Countdown

    Hi
    Ich brauche dringend jemanden der mir hierbei helfen kann .

    PHP-Code:

    <?

    function link_or_not($haustyp_end,$haustyp_link,$haus_ready)
       {

        if($haustyp_end==0) {
             print $haustyp_link; }

        if($haus_ready==1) {
             print "-"; }

        if($haustyp_end>0 && $haus_ready==0) {
              $bau_rest=$haustyp_end-time();
             echo gmdate("<b>H:i:s</b>" , $bau_rest);  }

       }

    ?>
    <html><body ><head><link rel=stylesheet href=images/styles.css type=text/css></head>
    <br><br><br><br>
    <div align=center>
    <table border="1" >


    <tr ><td colspan=7><b>Holzfäller</b></td></tr>

    <tr >
         <td width=110>Holzfäller [1]</td>
         <td align=center width=70><?print $hf1_taler;?></td>
         <td align=center width=70><?print $hf1_holz;?></td>
         <td align=center width=70><?print $hf1_eisen;?></td>
         <td align=center width=70><?print $hf1_stein;?></td>
         <td align=center width=100>00:00:30 Stunden</td>
         <td align=center width=110><? link_or_not($hf1_end,$hf1_link,$hf1); ?></td>

    <? if($hf1==1) { echo "

    <tr >
         <td width=110>Holzfäller [2]</td>
         <td align=center width=70> $hf2_taler</td>
         <td align=center width=70> $hf2_holz</td>
         <td align=center width=70> $hf2_eisen</td>
         <td align=center width=70> $hf2_stein</td>
         <td align=center width=100>00:00:30 Stunden</td>
         <td align=center width=110>"; link_or_not($hf2_end,$hf2_link,$hf2); print "</td>
    </tr>
    </tr>"; }    ?>

    <? if($hf2==1) { echo "

    <tr >
         <td width=110>Holzfäller [3]</td>
         <td align=center width=70> $hf3_taler</td>
         <td align=center width=70> $hf3_holz</td>
         <td align=center width=70> $hf3_eisen</td>
         <td align=center width=70> $hf3_stein</td>
         <td align=center width=100>00:00:30 Stunden</td>
         <td align=center width=110>"; link_or_not($hf3_end,$hf3_link,$hf3); print "</td>
    </tr>
    </tr>"; } ?>

    <? if($hf3==1) { echo "

    <tr >
         <td width=110>Holzfäller [4]</td>
         <td align=center width=70>$hf4_taler</td>
         <td align=center width=70>$hf4_holz</td>
         <td align=center width=70>$hf4_eisen</td>
         <td align=center width=70>$hf4_stein</td>
         <td align=center width=100>00:00:30 Stunden</td>
         <td align=center width=110>"; link_or_not($hf4_end,$hf4_link,$hf4); print "</td>
    </tr>
    </tr>"; } ?>
    So ... oben haben wir ein Funktion welche bestimmt ob da ein Link ($haustyp_link) , ein Strich (-) oder eine Zeit ausgegeben wird .

    Mein Probllem ist die zeit . Hierbei wird sie als ganz nomaler text ausgegeben . Ich will sie aber als Countdwn (per JavaScript) runterlaufen lassen (im Sekundenschritt) ....

    Ich habe schon ein javaScript gefunden mit dem das möglch ist :

    Code:
    g_timer = new Array();
    
    function setDivText(c1, text)
    {
    document.getElementById(c1).innerHTML=text;
    }
    
    function addTimer(seconds, divName)
    {
            for (i=0; i<g_timer.length; i++)
            {
                    if (g_timer[i] == -1)
                            break;
            }
            g_timer[i] = seconds;
            g_timer[i+1] = divName;
    }
    
    function countdown()
    {
            len = g_timer.length*2;
            for (i=0; i<len;i+=2)
            {
                    if (g_timer[i] > 0)
                    {
                            if (--g_timer[i] > 0)
                            {
                                    lSeconds = g_timer[i]%60;                // bisserl komplizierte Formatierung
                                    lMinutes = Math.floor(g_timer[i] / 60);
                                    lHours = Math.floor(lMinutes / 60);
                                    lMinutes%=60;
                                    lMinutes= ((lMinutes<10)? "0" : "" ) +  (lMinutes);
                                    lSeconds =((lSeconds<10)?"0":"") +  (lSeconds);
                                    var ebene=g_timer[i+1];
                                    setDivText(ebene, "<span class='timer'>" + lHours + ":" + lMinutes + ":" + lSeconds +"</span>");
                            }
                            else
                            {
                                    setDivText(g_timer[i+1], "<span class='timer'>[fertig]</span>");
                                    g_timer[i]=-1; // als 'wieder frei' markieren
                            }
                    }
            }
            setTimeout("countdown()", 999);
    Nun hab ich keinen Plan wie das geht und bitte jemanden das mal zu versuchen reinzubasteln ....

    Wäre sehr dankar

    Gruß
    inq39

  • #2
    Man muss halt irgendwie $bau_rest (in der function) in das javascript bekommen , und dieses dann noch einfügen .....

    Hat wirklich niemand Plan davon

    Kommentar


    • #3
      Habe hier noch ein Countdown Script gefunden :

      Code:
      <script language="JavaScript">
      <!--//Zeit Bis zum Start
      var SEC = 60;var MIN = 59;var STD = 1;
      setInterval("startCountdown()",1000)
      function startCountdown(){ 
      if(MIN >= 10 && (SEC - 1) >= 10) {  
        SEC = SEC - 1;  
        numberCountdown.innerText = STD + ":" + MIN + "." + SEC;
      } else if(MIN >= 10 && (SEC - 1) < 10 && (SEC - 1) >= 0) {
        SEC = SEC - 1;  
        numberCountdown.innerText = STD + ":" + MIN + ".0" + SEC; 
      } else if( MIN < 10 && MIN >= 0 && (SEC - 1) < 10 && (SEC - 1) >= 0) {
        SEC = SEC - 1;  
        numberCountdown.innerText = STD + ":0" + MIN + ".0" + SEC;
      } else if(MIN < 10 && MIN >= 0 && (SEC - 1) >= 10) {
        SEC = SEC - 1;
        numberCountdown.innerText = STD + ":0" + MIN + "." + SEC; 
      } else if((MIN - 1) >= 10 && SEC == 0) {
        SEC = 59;  MIN = MIN - 1;  
        numberCountdown.innerText = STD + ":" + MIN + "." + SEC;
      } else if((MIN - 1) < 10 && (MIN - 1) >= 0 && SEC == 0) {
        SEC = 59;  MIN = MIN - 1;  numberCountdown.innerText = STD + ":0" + MIN + "." + SEC; 
      } else if(MIN == 0 && SEC == 0) {  
        STD = STD - 1;  MIN = 59;  SEC = 59;  
        numberCountdown.innerText = STD + ":" + MIN + "." + SEC; 
      }
      }
      //-->
      </script>
      <div align="center">Noch <div id="numberCountdown">2:00:00</div>Std. bis es 2 Std. später ist als jetzt</div></p>
      Ist das ein besseres ?

      Kommentar


      • #4
        nagut nochmal ganz einfach :

        Ich will wissen wie man folgendes verwirklicht :

        Ich habe php erstmal . dort definiere ich eine Variable . Diese Variable gibt mir eine Zahl welche Sekunden darstellen sollen . Diese sekunden solen dann ausgegeben werden mittels Javascript

        Undzwar soll es ein Countdown werden (H.m.s) welcher rückwerts im Sekundentakt bis 0 zählt

        Ist ds wirklich so schwer zu verstehen oder ist es so kompliziert zu machen

        Kommentar


        • #5
          na dann beschäftige dich doch selber mal ein bisschen damit.

          wenn du hier nur was in den raum wirfst und sagst "macht mal!", dann ist es doch nicht allzu verwunderlich, wenn keiner bock hat darauf zu antworten...

          also, eine countdown-funktion hast du ja schon gefunden.

          dieser musst du jetzt also den sekunden-wert übergeben.

          das sollte eigentlich kein problem sein, einfach in den funktionsaufruf per php deine variable reinschreiben.
          I don't believe in rebirth. Actually, I never did in my whole lives.

          Kommentar


          • #6
            hallo inq39,

            probiers mal so:
            PHP-Code:
            <?

            function link_or_not($haustyp_end,$haustyp_link,$haus_ready)
               {

                if($haustyp_end==0) {
                     print $haustyp_link; }

                if($haus_ready==1) {
                     print "-"; }

                if($haustyp_end>0 && $haus_ready==0) {
                      $bau_rest=$haustyp_end-time();
                     echo $bau_rest;  }

               }

            ?>

            <html><body ><head><link rel=stylesheet href=images/styles.css type=text/css>
            <script type="text/javascript">
            <!--
            var diffMonths=-1, diffDays=-1, diffHours=-1, diffMins=-1
            var deinezeit = 0
            var compDat = 0
            var zeit = 0
            var msPerMonth = 31 * 24 * 60 * 60 * 1000
            var msPerDay = 24 * 60 * 60 * 1000
            var msPerHour = 60 * 60 * 1000
            var msPerMin = 60 * 1000
            var msPerSec = 1000
            var startvar = 0

            function clock(){
                if (startvar==0){
                    deinezeit = document.getElementById('zeit').innerHTML
                    compDat = new Date()
                    zeit = compDat.getTime() + (deinezeit * 1000)
                    startvar = 1
                    }
                 var today = new Date()
                 var changeD = diffDays
                 var changeH = diffHours
                 var changeMin = diffMins     
                 var diffMs = zeit - today.getTime()
                 diffDays = Math.floor(diffMs / msPerDay)
                 diffMs -= diffDays * msPerDay
                 diffHours = Math.floor(diffMs / msPerHour)
                 diffMs -= diffHours * msPerHour
                 diffMins = Math.floor(diffMs / msPerMin)
                 diffMs -= diffMins * msPerMin
                 var diffSecs = Math.floor(diffMs / msPerSec)     
                 document.getElementById('zeit').innerHTML =diffHours+":"+diffMins+":"+diffSecs;
                 if(diffDays!=0 || diffHours!=0 || diffMins!=0 || diffSecs!=0)
                 {
                 timerID = setTimeout("clock()",1000)
                 }
                 }
            // -->
            </script>
            </head>
            <body onLoad="clock()">
            <br><br><br><br>
            <div align=center>
            <table border="1" >


            <tr ><td colspan=7><b>Holzfäller</b></td></tr>

            <tr >
                 <td width=110>Holzfäller [1]</td>
                 <td align=center width=70><?print $hf1_taler;?></td>
                 <td align=center width=70><?print $hf1_holz;?></td>
                 <td align=center width=70><?print $hf1_eisen;?></td>
                 <td align=center width=70><?print $hf1_stein;?></td>
                 <td align=center width=100>00:00:30 Stunden</td>
                 <td id= "zeit" align=center width=110><? link_or_not($hf1_end,$hf1_link,$hf1); ?></td>

            <? if($hf1==1) { echo "

            <tr >
                 <td width=110>Holzfäller [2]</td>
                 <td align=center width=70> $hf2_taler</td>
                 <td align=center width=70> $hf2_holz</td>
                 <td align=center width=70> $hf2_eisen</td>
                 <td align=center width=70> $hf2_stein</td>
                 <td align=center width=100>00:00:30 Stunden</td>
                 <td id= \"zeit\" align=center width=110>"; link_or_not($hf2_end,$hf2_link,$hf2); print "</td>
            </tr>
            </tr>"; }    ?>

            <? if($hf2==1) { echo "

            <tr >
                 <td width=110>Holzfäller [3]</td>
                 <td align=center width=70> $hf3_taler</td>
                 <td align=center width=70> $hf3_holz</td>
                 <td align=center width=70> $hf3_eisen</td>
                 <td align=center width=70> $hf3_stein</td>
                 <td align=center width=100>00:00:30 Stunden</td>
                 <td id= \"zeit\" align=center width=110>"; link_or_not($hf3_end,$hf3_link,$hf3); print "</td>
            </tr>
            </tr>"; } ?>

            <? if($hf3==1) { echo "

            <tr >
                 <td width=110>Holzfäller [4]</td>
                 <td align=center width=70>$hf4_taler</td>
                 <td align=center width=70>$hf4_holz</td>
                 <td align=center width=70>$hf4_eisen</td>
                 <td align=center width=70>$hf4_stein</td>
                 <td align=center width=100>00:00:30 Stunden</td>
                 <td id= \"zeit\" align=center width=110>"; link_or_not($hf4_end,$hf4_link,$hf4); print "</td>
            </tr>
            </tr>"; } ?>
            habs nicht getestet sollte aber funktionieren...

            Kommentar


            • #7
              HI

              danke erstmal ...

              aber es gibt n prob dabei ....

              Hier nochmal die Function :

              PHP-Code:
              function link_or_not($haustyp_end,$haustyp_link,$haus_ready)
                 {

                  if(
              $haustyp_end==0) {
                       print 
              $haustyp_link; }

                  if(
              $haus_ready==1) {
                       print 
              "-"; }

                  if(
              $haustyp_end>&& $haus_ready==0) {
                        
              $bau_rest=$haustyp_end-time();
                       echo 
              $bau_rest;  }

                 } 
              Also im Fall if($haustyp_end>0 && $haus_ready==0) gibt er den Timer aus so wie er auch soll - DANKE !!!!
              Bloßß wenn der timestamp kleiner time() ist dann speichert er nicht den neuen wert
              der Timer läuft dann immer bei 24 stunden neu an

              UND:
              Wenn if($haustyp_end==0) der Fall ist zeigt er das an : NaN:NaN:NaN
              das ganze lässt sich auch nit richtig markieren (MArkierung geht immer weg) ..... Das gleiche auch bei if($haus_ready==1) ...


              was ist da falsch ... kannst du mir nochmal so helfen wie schonmal ?

              P.S ist es möglich die Zeit im Timer immer 2-stellig anzuzeigen ?

              Kommentar


              • #8
                hallo,

                so, habe mir das Ganze nochmal angeschaut:

                PHP-Code:
                <?

                function link_or_not($haustyp_end,$haustyp_link,$haus_ready)
                   {

                    if($haustyp_end==0) {
                         print $haustyp_link; }

                    if($haus_ready==1) {
                         print "-"; }

                    if($haustyp_end>0 && $haus_ready==0) {
                          $bau_rest=$haustyp_end-time();
                         echo $bau_rest;  }

                   }

                ?>

                <html><body ><head><link rel=stylesheet href=images/styles.css type=text/css>
                <script type="text/javascript">
                <!--
                var diffMonths=-1, diffDays=-1, diffHours=-1, diffMins=-1;
                var deinezeit1=0, deinezeit2=0, deinezeit3=0, deinezeit4=0;
                var startvar1=0, startvar2=0, startvar3=0, startvar4=0;
                var zeit1=0, zeit2=0, zeit3=0, zeit4=0;
                var compDat = 0;
                var msPerMonth = 31 * 24 * 60 * 60 * 1000;
                var msPerDay = 24 * 60 * 60 * 1000;
                var msPerHour = 60 * 60 * 1000;
                var msPerMin = 60 * 1000;
                var msPerSec = 1000;

                function init(){
                    if (isNaN(document.getElementById('zeit1').innerHTML)==false){    
                    setTimeout("clock()",1);
                    }
                    
                    if (isNaN(document.getElementById('zeit2').innerHTML)==false){    
                    setTimeout("clock2()",1);
                    }
                    
                    if (isNaN(document.getElementById('zeit3').innerHTML)==false){    
                    setTimeout("clock3()",1);
                    }
                    
                    if (isNaN(document.getElementById('zeit4').innerHTML)==false){   
                    setTimeout("clock4()",1);
                    }
                }

                function clock(){
                    if (startvar1==0){
                        deinezeit1 = document.getElementById('zeit1').innerHTML;     
                        compDat = new Date();
                        zeit1 = compDat.getTime() + (deinezeit1 * 1000);
                        startvar1 = 1;
                     }
                     var today = new Date();   
                     var diffMs = zeit1 - today.getTime();
                     diffDays = Math.floor(diffMs / msPerDay);
                     diffMs -= diffDays * msPerDay;
                     diffHours = Math.floor(diffMs / msPerHour);
                     diffMs -= diffHours * msPerHour;
                     diffMins = Math.floor(diffMs / msPerMin);
                     diffMs -= diffMins * msPerMin;
                     var diffSecs = Math.floor(diffMs / msPerSec); 
                     diffHours= ((diffHours<10)? "0" : "" ) +  (diffHours);
                     diffMins= ((diffMins<10)? "0" : "" ) +  (diffMins);
                     diffSecs= ((diffSecs<10)? "0" : "" ) +  (diffSecs);    
                     document.getElementById('zeit1').innerHTML =diffHours+":"+diffMins+":"+diffSecs;
                     if(diffDays!=0 || diffHours!=0 || diffMins!=0 || diffSecs!=0){
                     setTimeout("clock()",1000);
                     }
                }
                     
                function clock2(){
                    if (startvar2==0){
                        deinezeit2 = document.getElementById('zeit2').innerHTML;
                        compDat = new Date();
                        zeit2 = compDat.getTime() + (deinezeit2 * 1000);
                        startvar2 = 1;
                     }
                     var today = new Date();   
                     var diffMs = zeit2 - today.getTime();
                     diffDays = Math.floor(diffMs / msPerDay);
                     diffMs -= diffDays * msPerDay;
                     diffHours = Math.floor(diffMs / msPerHour);
                     diffMs -= diffHours * msPerHour;
                     diffMins = Math.floor(diffMs / msPerMin);
                     diffMs -= diffMins * msPerMin;
                     var diffSecs = Math.floor(diffMs / msPerSec); 
                     diffHours= ((diffHours<10)? "0" : "" ) +  (diffHours);
                     diffMins= ((diffMins<10)? "0" : "" ) +  (diffMins);
                     diffSecs= ((diffSecs<10)? "0" : "" ) +  (diffSecs);    
                     document.getElementById('zeit2').innerHTML =diffHours+":"+diffMins+":"+diffSecs;
                     if(diffDays!=0 || diffHours!=0 || diffMins!=0 || diffSecs!=0)
                     {
                     setTimeout("clock2()",1000);
                     }
                }
                     
                function clock3(){
                    if (startvar3==0){
                        deinezeit3 = document.getElementById('zeit3').innerHTML;
                        compDat = new Date();
                        zeit3 = compDat.getTime() + (deinezeit3 * 1000);
                        startvar3 = 1;
                     }
                     var today = new Date();    
                     var diffMs = zeit3 - today.getTime();
                     diffDays = Math.floor(diffMs / msPerDay);
                     diffMs -= diffDays * msPerDay;
                     diffHours = Math.floor(diffMs / msPerHour);
                     diffMs -= diffHours * msPerHour;
                     diffMins = Math.floor(diffMs / msPerMin);
                     diffMs -= diffMins * msPerMin;
                     var diffSecs = Math.floor(diffMs / msPerSec); 
                     diffHours= ((diffHours<10)? "0" : "" ) +  (diffHours);
                     diffMins= ((diffMins<10)? "0" : "" ) +  (diffMins);
                     diffSecs= ((diffSecs<10)? "0" : "" ) +  (diffSecs);    
                     document.getElementById('zeit3').innerHTML =diffHours+":"+diffMins+":"+diffSecs;
                     if(diffDays!=0 || diffHours!=0 || diffMins!=0 || diffSecs!=0)
                     {
                     setTimeout("clock3()",1000);
                     }
                }
                     
                function clock4(){
                    if (startvar4==0){
                        deinezeit4 = document.getElementById('zeit4').innerHTML;
                        compDat = new Date()
                        zeit4 = compDat.getTime() + (deinezeit4 * 1000);
                        startvar4 = 1;
                     }
                     var today = new Date();    
                     var diffMs = zeit4 - today.getTime();
                     diffDays = Math.floor(diffMs / msPerDay);
                     diffMs -= diffDays * msPerDay;
                     diffHours = Math.floor(diffMs / msPerHour);
                     diffMs -= diffHours * msPerHour;
                     diffMins = Math.floor(diffMs / msPerMin);
                     diffMs -= diffMins * msPerMin;
                     var diffSecs = Math.floor(diffMs / msPerSec); 
                     diffHours= ((diffHours<10)? "0" : "" ) +  (diffHours);
                     diffMins= ((diffMins<10)? "0" : "" ) +  (diffMins);
                     diffSecs= ((diffSecs<10)? "0" : "" ) +  (diffSecs);    
                     document.getElementById('zeit4').innerHTML =diffHours+":"+diffMins+":"+diffSecs;
                     if(diffDays!=0 || diffHours!=0 || diffMins!=0 || diffSecs!=0)
                     {
                     setTimeout("clock4()",1000);
                     }
                }
                // -->
                </script>
                </head>
                <body onLoad="init()">
                <br><br><br><br>
                <div align=center>
                <table border="1" >


                <tr ><td colspan=7><b>Holzfäller</b></td></tr>

                <tr >
                     <td width=110>Holzfäller [1]</td>
                     <td align=center width=70><?print $hf1_taler;?></td>
                     <td align=center width=70><?print $hf1_holz;?></td>
                     <td align=center width=70><?print $hf1_eisen;?></td>
                     <td align=center width=70><?print $hf1_stein;?></td>
                     <td align=center width=100>00:00:30 Stunden</td>
                     <td id= "zeit1" align=center width=110><? link_or_not($hf1_end,$hf1_link,$hf1); ?></td>

                <? if($hf1==1) { echo "

                <tr >
                     <td width=110>Holzfäller [2]</td>
                     <td align=center width=70> $hf2_taler</td>
                     <td align=center width=70> $hf2_holz</td>
                     <td align=center width=70> $hf2_eisen</td>
                     <td align=center width=70> $hf2_stein</td>
                     <td align=center width=100>00:00:30 Stunden</td>
                     <td id= \"zeit2\" align=center width=110>"; link_or_not($hf2_end,$hf2_link,$hf2); print "</td>
                </tr>
                </tr>"; }    ?>

                <? if($hf2==1) { echo "

                <tr >
                     <td width=110>Holzfäller [3]</td>
                     <td align=center width=70> $hf3_taler</td>
                     <td align=center width=70> $hf3_holz</td>
                     <td align=center width=70> $hf3_eisen</td>
                     <td align=center width=70> $hf3_stein</td>
                     <td align=center width=100>00:00:30 Stunden</td>
                     <td id= \"zeit3\" align=center width=110>"; link_or_not($hf3_end,$hf3_link,$hf3); print "</td>
                </tr>
                </tr>"; } ?>

                <? if($hf3==1) { echo "

                <tr >
                     <td width=110>Holzfäller [4]</td>
                     <td align=center width=70>$hf4_taler</td>
                     <td align=center width=70>$hf4_holz</td>
                     <td align=center width=70>$hf4_eisen</td>
                     <td align=center width=70>$hf4_stein</td>
                     <td align=center width=100>00:00:30 Stunden</td>
                     <td id= \"zeit4\" align=center width=110>"; link_or_not($hf4_end,$hf4_link,$hf4); print "</td>
                </tr>
                </tr>"; } ?>
                also, die Zeit wird nun 2stellig angezeigt,
                wenn if($haustyp_end==0) der Fall ist sollte nun $haustyp_link angezeigt werden, und wenn if($haus_ready==1) der Fall ist sollte - angezeigt werden.
                Bloßß wenn der timestamp kleiner time() ist dann speichert er nicht den neuen wert
                der Timer läuft dann immer bei 24 stunden neu an
                was meinst du mit: speichert er nicht den neuen Wert
                was sollte er denn bei timestamp < time() anzeigen?

                Jeder Holzfäller [1],[2],[3],[4], hat nun einen eigenen counter, so kann nun wenn mehrere Holzfäller angezeigt werden, jeder holzfäller einen counter haben (funktionierte vorher nicht). Wenn noch weitere Holzfäller dazukommen, müsste natürlich auch das javascript angepasst werden.

                Was wird das Ganze eigentlich wenn es fertig ist??

                gruss freaxx

                Kommentar


                • #9
                  hi

                  jetzt funzt es perfekt

                  Bloß wenn ich weitere dazu tu gibts probs :

                  Code:
                  function clock5(){
                  if (startvar5==0){
                  deinezeit5 = document.getElementById('zeit5').innerHTML;
                  compDat = new Date()
                  zeit5 = compDat.getTime() + (deinezeit5 * 1000);
                  startvar5 = 1;
                  }
                  var today = new Date();
                  var diffMs = zeit5 - today.getTime();
                  diffDays = Math.floor(diffMs / msPerDay);
                  diffMs -= diffDays * msPerDay;
                  diffHours = Math.floor(diffMs / msPerHour);
                  diffMs -= diffHours * msPerHour;
                  diffMins = Math.floor(diffMs / msPerMin);
                  diffMs -= diffMins * msPerMin;
                  var diffSecs = Math.floor(diffMs / msPerSec);
                  diffHours= ((diffHours<10)? "0" : "" ) + (diffHours);
                  diffMins= ((diffMins<10)? "0" : "" ) + (diffMins);
                  diffSecs= ((diffSecs<10)? "0" : "" ) + (diffSecs);
                  document.getElementById('zeit5').innerHTML =diffHours+":"+diffMins+":"+diffSecs;
                  if(diffDays!=0 || diffHours!=0 || diffMins!=0 || diffSecs!=0)
                  {
                  setTimeout("clock5()",1000);
                  }
                  }
                  ....ist doch i.O. , oder ?

                  geht jedenfalls nicht und es wird wieder ganz normal angezeigt (aber nur beim 5er und den neuen halt) ....

                  Und kann man das nicht irgendwie in die function bringen dass ich das JS nur einmal haben muss ?

                  Kommentar


                  • #10
                    ja, scheint korrekt,
                    musst aber auch die Variabeln und function init ergänzen:

                    PHP-Code:
                    var deinezeit1=0deinezeit2=0deinezeit3=0deinezeit4=0deinezeit5=0;
                    var 
                    startvar1=0startvar2=0startvar3=0startvar4=0,startvar5=0;
                    var 
                    zeit1=0zeit2=0zeit3=0zeit4=0,zeit5=0
                    PHP-Code:
                    if (isNaN(document.getElementById('zeit5').innerHTML)==false){   
                        
                    setTimeout("clock5()",1);
                        } 
                    freaxx

                    Kommentar


                    • #11
                      hmm .... schaut bei mir jetzt so aus :

                      PHP-Code:
                      <html><body ><head><link rel=stylesheet href=images/styles.css type=text/css> 
                      <script type="text/javascript"> 
                      <!-- 
                      var diffMonths=-1, diffDays=-1, diffHours=-1, diffMins=-1; 
                      var deinezeit1=0, deinezeit2=0, deinezeit3=0, deinezeit4=0, deinezeit5=0; 
                      var startvar1=0, startvar2=0, startvar3=0, startvar4=0, startvar5=0; 
                      var zeit1=0, zeit2=0, zeit3=0, zeit4=0, zeit5=0; 
                      var compDat = 0; 
                      var msPerMonth = 31 * 24 * 60 * 60 * 1000; 
                      var msPerDay = 24 * 60 * 60 * 1000; 
                      var msPerHour = 60 * 60 * 1000; 
                      var msPerMin = 60 * 1000; 
                      var msPerSec = 1000; 

                      function init(){ 
                      if (isNaN(document.getElementById('zeit1').innerHTML)==false){ 
                      setTimeout("clock()",1); 


                      if (isNaN(document.getElementById('zeit2').innerHTML)==false){ 
                      setTimeout("clock2()",1); 


                      if (isNaN(document.getElementById('zeit3').innerHTML)==false){ 
                      setTimeout("clock3()",1); 


                      if (isNaN(document.getElementById('zeit4').innerHTML)==false){ 
                      setTimeout("clock4()",1); 


                      if (isNaN(document.getElementById('zeit5').innerHTML)==false){ 
                      setTimeout("clock5()",1); 



                      function clock(){ 
                      if (startvar1==0){ 
                      deinezeit1 = document.getElementById('zeit1').innerHTML; 
                      compDat = new Date(); 
                      zeit1 = compDat.getTime() + (deinezeit1 * 1000); 
                      startvar1 = 1; 

                      var today = new Date(); 
                      var diffMs = zeit1 - today.getTime(); 
                      diffDays = Math.floor(diffMs / msPerDay); 
                      diffMs -= diffDays * msPerDay; 
                      diffHours = Math.floor(diffMs / msPerHour); 
                      diffMs -= diffHours * msPerHour; 
                      diffMins = Math.floor(diffMs / msPerMin); 
                      diffMs -= diffMins * msPerMin; 
                      var diffSecs = Math.floor(diffMs / msPerSec); 
                      diffHours= ((diffHours<10)? "0" : "" ) + (diffHours); 
                      diffMins= ((diffMins<10)? "0" : "" ) + (diffMins); 
                      diffSecs= ((diffSecs<10)? "0" : "" ) + (diffSecs); 
                      document.getElementById('zeit1').innerHTML =diffHours+":"+diffMins+":"+diffSecs; 
                      if(diffDays!=0 || diffHours!=0 || diffMins!=0 || diffSecs!=0){ 
                      setTimeout("clock()",1000); 



                      function clock2(){ 
                      if (startvar2==0){ 
                      deinezeit2 = document.getElementById('zeit2').innerHTML; 
                      compDat = new Date(); 
                      zeit2 = compDat.getTime() + (deinezeit2 * 1000); 
                      startvar2 = 1; 

                      var today = new Date(); 
                      var diffMs = zeit2 - today.getTime(); 
                      diffDays = Math.floor(diffMs / msPerDay); 
                      diffMs -= diffDays * msPerDay; 
                      diffHours = Math.floor(diffMs / msPerHour); 
                      diffMs -= diffHours * msPerHour; 
                      diffMins = Math.floor(diffMs / msPerMin); 
                      diffMs -= diffMins * msPerMin; 
                      var diffSecs = Math.floor(diffMs / msPerSec); 
                      diffHours= ((diffHours<10)? "0" : "" ) + (diffHours); 
                      diffMins= ((diffMins<10)? "0" : "" ) + (diffMins); 
                      diffSecs= ((diffSecs<10)? "0" : "" ) + (diffSecs); 
                      document.getElementById('zeit2').innerHTML =diffHours+":"+diffMins+":"+diffSecs; 
                      if(diffDays!=0 || diffHours!=0 || diffMins!=0 || diffSecs!=0) 

                      setTimeout("clock2()",1000); 



                      function clock3(){ 
                      if (startvar3==0){ 
                      deinezeit3 = document.getElementById('zeit3').innerHTML; 
                      compDat = new Date(); 
                      zeit3 = compDat.getTime() + (deinezeit3 * 1000); 
                      startvar3 = 1; 

                      var today = new Date(); 
                      var diffMs = zeit3 - today.getTime(); 
                      diffDays = Math.floor(diffMs / msPerDay); 
                      diffMs -= diffDays * msPerDay; 
                      diffHours = Math.floor(diffMs / msPerHour); 
                      diffMs -= diffHours * msPerHour; 
                      diffMins = Math.floor(diffMs / msPerMin); 
                      diffMs -= diffMins * msPerMin; 
                      var diffSecs = Math.floor(diffMs / msPerSec); 
                      diffHours= ((diffHours<10)? "0" : "" ) + (diffHours); 
                      diffMins= ((diffMins<10)? "0" : "" ) + (diffMins); 
                      diffSecs= ((diffSecs<10)? "0" : "" ) + (diffSecs); 
                      document.getElementById('zeit3').innerHTML =diffHours+":"+diffMins+":"+diffSecs; 
                      if(diffDays!=0 || diffHours!=0 || diffMins!=0 || diffSecs!=0) 

                      setTimeout("clock3()",1000); 



                      function clock4(){ 
                      if (startvar4==0){ 
                      deinezeit4 = document.getElementById('zeit4').innerHTML; 
                      compDat = new Date() 
                      zeit4 = compDat.getTime() + (deinezeit4 * 1000); 
                      startvar4 = 1; 

                      var today = new Date(); 
                      var diffMs = zeit4 - today.getTime(); 
                      diffDays = Math.floor(diffMs / msPerDay); 
                      diffMs -= diffDays * msPerDay; 
                      diffHours = Math.floor(diffMs / msPerHour); 
                      diffMs -= diffHours * msPerHour; 
                      diffMins = Math.floor(diffMs / msPerMin); 
                      diffMs -= diffMins * msPerMin; 
                      var diffSecs = Math.floor(diffMs / msPerSec); 
                      diffHours= ((diffHours<10)? "0" : "" ) + (diffHours); 
                      diffMins= ((diffMins<10)? "0" : "" ) + (diffMins); 
                      diffSecs= ((diffSecs<10)? "0" : "" ) + (diffSecs); 
                      document.getElementById('zeit4').innerHTML =diffHours+":"+diffMins+":"+diffSecs; 
                      if(diffDays!=0 || diffHours!=0 || diffMins!=0 || diffSecs!=0) 

                      setTimeout("clock4()",1000); 



                      function clock5(){ 
                      if (startvar5==0){ 
                      deinezeit5 = document.getElementById('zeit5').innerHTML; 
                      compDat = new Date() 
                      zeit5 = compDat.getTime() + (deinezeit5 * 1000); 
                      startvar5 = 1; 

                      var today = new Date(); 
                      var diffMs = zeit5 - today.getTime(); 
                      diffDays = Math.floor(diffMs / msPerDay); 
                      diffMs -= diffDays * msPerDay; 
                      diffHours = Math.floor(diffMs / msPerHour); 
                      diffMs -= diffHours * msPerHour; 
                      diffMins = Math.floor(diffMs / msPerMin); 
                      diffMs -= diffMins * msPerMin; 
                      var diffSecs = Math.floor(diffMs / msPerSec); 
                      diffHours= ((diffHours<10)? "0" : "" ) + (diffHours); 
                      diffMins= ((diffMins<10)? "0" : "" ) + (diffMins); 
                      diffSecs= ((diffSecs<10)? "0" : "" ) + (diffSecs); 
                      document.getElementById('zeit5').innerHTML =diffHours+":"+diffMins+":"+diffSecs; 
                      if(diffDays!=0 || diffHours!=0 || diffMins!=0 || diffSecs!=0) 

                      setTimeout("clock5()",1000); 


                      // --> 
                      </script> 
                      </head> 
                      <body onLoad="init()"> 
                      <br><br><br><br> 
                      <div align=center> 
                      <table border="1" >


                      <tr >
                           <td align=center><b>Gebäude</b></td>
                           <td align=center><b>Taler</b></td>
                           <td align=center><b>Holz</b></td>
                           <td align=center><b>Eisen</b></td>
                           <td align=center><b>Stein</b></td>
                           <td align=center><b>Zeit</b></td>
                           <td align=center><b>Aktion</b></td>
                      </tr>

                      <tr ><td colspan=7><b>Holzfäller</b></td></tr>

                      <tr >
                           <td width=110><a href=info.php?info=1>Holzfäller [1]</a></td>
                           <td align=center width=70><?print $hf1_taler;?></td>
                           <td align=center width=70><?print $hf1_holz;?></td>
                           <td align=center width=70><?print $hf1_eisen;?></td>
                           <td align=center width=70><?print $hf1_stein;?></td>
                           <td align=center width=100>00:00:30 Stunden</td>
                           <td id= "zeit1" align=center width=110><? link_or_not($hf1_end,$hf1_link,$hf1); ?></td>

                      <? if($hf1==1) { echo "

                      <tr >
                           <td width=110><a href=info.php?info=2>Holzfäller [2]</a></td>
                           <td align=center width=70> $hf2_taler</td>
                           <td align=center width=70> $hf2_holz</td>
                           <td align=center width=70> $hf2_eisen</td>
                           <td align=center width=70> $hf2_stein</td>
                           <td align=center width=100>00:00:30 Stunden</td>
                           <td id= \"zeit2\" align=center width=110>"; link_or_not($hf2_end,$hf2_link,$hf2); print "</td>
                      </tr>
                      </tr>"; }    ?>

                      <? if($hf2==1) { echo "

                      <tr >
                           <td width=110><a href=info.php?info=3>Holzfäller [3]</a></td>
                           <td align=center width=70> $hf3_taler</td>
                           <td align=center width=70> $hf3_holz</td>
                           <td align=center width=70> $hf3_eisen</td>
                           <td align=center width=70> $hf3_stein</td>
                           <td align=center width=100>00:00:30 Stunden</td>
                           <td id= \"zeit3\" align=center width=110>"; link_or_not($hf3_end,$hf3_link,$hf3); print "</td>
                      </tr>
                      </tr>"; } ?>

                      <? if($hf3==1) { echo "

                      <tr >
                           <td width=110><a href=info.php?info=4>Holzfäller [4]</a></td>
                           <td align=center width=70>$hf4_taler</td>
                           <td align=center width=70>$hf4_holz</td>
                           <td align=center width=70>$hf4_eisen</td>
                           <td align=center width=70>$hf4_stein</td>
                           <td align=center width=100>00:00:30 Stunden</td>
                           <td id= \"zeit4\" align=center width=110>"; link_or_not($hf4_end,$hf4_link,$hf4); print "</td>
                      </tr>
                      </tr>"; } ?>

                      <tr ><td colspan=7><b>Eisenschmelzen</b></td></tr>




                      <tr >
                      <td width=110><a href=info.php?info=5>Eisenschmelze [1]</a></td>
                      <td align=center width=70><?print $es1_taler;?></td>
                      <td align=center width=70><?print $es1_holz;?></td>
                      <td align=center width=70><?print $es1_eisen;?></td>
                      <td align=center width=70><?print $es1_stein;?></td>
                      <td align=center width=100>00:00:30 Stunden</td>
                      <td id= "zeit5" align=center width=110><? link_or_not($es1_end,$es1_link,$es1); ?></td>
                      und geht nicht
                      Also nur beim 5. gehts nicht

                      Kommentar


                      • #12
                        hallo, habe das Ganze mal geändert, das JS hat jetzt nur noch ein clock, und mittels php wird nur soviel JS ausgegeben wie nötig.
                        PHP-Code:
                        <script type="text/javascript"> 
                        <!--
                        var diffMonths=-1, diffDays=-1, diffHours=-1, diffMins=-1;
                        var zeit1=0, zeit2=0, zeit3=0, zeit4=0, zeit5=0;
                        var compDat = new Date();
                        var msPerMonth = 31 * 24 * 60 * 60 * 1000;
                        var msPerDay = 24 * 60 * 60 * 1000;
                        var msPerHour = 60 * 60 * 1000;
                        var msPerMin = 60 * 1000;
                        var msPerSec = 1000;
                        var tdid1="zeit1",tdid2="zeit2",tdid3="zeit3",tdid4="zeit4",tdid5="zeit5";


                        function init(){
                        <? if($hf1_end>0 && $hf1==0) {echo "   
                            zeit1 = compDat.getTime() + (document.getElementById('zeit1').innerHTML * 1000);
                            clock(zeit1,tdid1);
                            ausgabe1 = window.setInterval(\"clock(zeit1,tdid1)\",1000);
                        "; }    ?>
                        <? if($hf1==1 && $hf2_end>0 && $hf2==0) { echo "    
                            zeit2 = compDat.getTime() + (document.getElementById('zeit2').innerHTML * 1000);
                            clock(zeit2,tdid2);
                            ausgabe2 = window.setInterval(\"clock(zeit2,tdid2)\",1000);
                            "; }    ?>
                        <? if($hf2==1 && $hf3_end>0 && $hf3==0) { echo "        
                            zeit3 = compDat.getTime() + (document.getElementById('zeit3').innerHTML * 1000);
                            clock(zeit3,tdid3);
                            ausgabe3 = window.setInterval(\"clock(zeit3,tdid3)\",1000);
                            "; }    ?>
                        <? if($hf3==1 &&$hf4_end>0 && $hf4==0) { echo "         
                            zeit4 = compDat.getTime() + (document.getElementById('zeit4').innerHTML * 1000);
                            clock(zeit4,tdid4);
                            ausgabe4 = window.setInterval(\"clock(zeit4,tdid4)\",1000);
                            "; }    ?>
                        <? if($es1_end>0 && $es1==0) { echo "         
                            zeit5 = compDat.getTime() + (document.getElementById('zeit5').innerHTML * 1000);
                            clock(zeit5,tdid5);
                            ausgabe5 = window.setInterval(\"clock(zeit5,tdid5)\",1000);
                            "; }    ?>
                            }

                        function clock(zeit,idtd){
                             var today = new Date();   
                             var diffMs = zeit - today.getTime();
                             diffDays = Math.floor(diffMs / msPerDay);
                             diffMs -= diffDays * msPerDay;
                             diffHours = Math.floor(diffMs / msPerHour);
                             diffMs -= diffHours * msPerHour;
                             diffMins = Math.floor(diffMs / msPerMin);
                             diffMs -= diffMins * msPerMin;
                             var diffSecs = Math.floor(diffMs / msPerSec); 
                             diffHours= ((diffHours<10)? "0" : "" ) +  (diffHours);
                             diffMins= ((diffMins<10)? "0" : "" ) +  (diffMins);
                             diffSecs= ((diffSecs<10)? "0" : "" ) +  (diffSecs);    
                             document.getElementById(idtd).innerHTML=diffHours+":"+diffMins+":"+diffSecs;
                             if(diffDays==0 && diffHours==0 && diffMins==0 && diffSecs==0){
                             switch(idtd) {
                             <? if($hf1_end>0 && $hf1==0) {echo "
                             case \"zeit1\":
                             window.clearInterval(ausgabe1);
                             break;"; } ?>
                             <? if($hf1==1 && $hf2_end>0 && $hf2==0) { echo " 
                             case \"zeit2\":
                             window.clearInterval(ausgabe2);
                             break;"; } ?>
                             <? if($hf2==1 && $hf3_end>0 && $hf3==0) { echo "
                             case \"zeit3\":
                             window.clearInterval(ausgabe3);
                             break;"; } ?>
                             <? if($hf3==1 &&$hf4_end>0 && $hf4==0) { echo "
                             case \"zeit4\":
                             window.clearInterval(ausgabe4);
                             break;"; } ?>
                             <? if($es1_end>0 && $es1==0) { echo "
                             case \"zeit5\":
                             window.clearInterval(ausgabe5);
                             break;"; } ?>
                             }
                             }
                        }
                        // -->
                        </script>
                        sollte auch beim 5 gehen...

                        Kommentar


                        • #13
                          geht ..
                          Zuletzt geändert von zuzu; 09.11.2002, 22:16.

                          Kommentar


                          • #14
                            Jo .. aber mich würde noch ne andere Variante interessieren

                            Undzwar das ganze in einer while Schlife :

                            PHP-Code:
                            $i 1;

                            $result mysql_query("SELECT autoid,anzahl,typ,ende FROM dung WHERE id='$last' ORDER BY ende ");

                            while(
                            $array mysql_fetch_array($result)) {

                            $rest_ausb=$array[ende]-time();


                            echo 
                            "
                            Es werden 
                            $array[anzahl] ";

                            print 
                            " in "; echo gmdate("H:i:s" $rest_ausb); print " Stunden bereitstehen.<br>";



                            Da genau das gleiche mit $rest_ausb ... man müsste das ganze dann ja auf ein JS runterschrauben . Habs probiert , ist mir aber nicht geglückt ... was muss man da noch groß beachten

                            Kommentar


                            • #15
                              hallo,
                              hier der code für die andere Variante:
                              PHP-Code:
                              <?php 
                              $i 
                              1;
                              $z 1;
                              $result mysql_query("SELECT autoid,anzahl,typ,ende FROM dung WHERE id='$last' ORDER BY ende ");

                              while(
                              $array mysql_fetch_array($result)) {

                              $rest_ausb=$array[ende]-time();

                              $tdid=$tdid."var tdid$z=\"zeit$z\"; ";
                              $zeit=$zeit."var zeit$z=0; ";
                              $init=$init."zeit$z = compDat.getTime() + (document.getElementById('zeit$z').innerHTML * 1000);
                              clock(zeit
                              $z,tdid$z);
                              ausgabe1 = window.setInterval(\"clock(zeit
                              $z,tdid$z)\",1000);
                              "
                              ;
                              $ende=$ende."case \"zeit$z\":
                              window.clearInterval(ausgabe
                              $z);
                              break;"
                              ;
                              $ausgabe=$ausgabe."Es werden $array[anzahl] in  <span id= \"zeit$z\">$rest_ausb</span> Stunden bereitstehen.</br>";
                              $z++;
                              ?>
                              <html><head>
                              <script type="text/javascript">
                              <!--
                              var diffMonths=-1, diffDays=-1, diffHours=-1, diffMins=-1;
                              var compDat = new Date();
                              var msPerMonth = 31 * 24 * 60 * 60 * 1000;
                              var msPerDay = 24 * 60 * 60 * 1000;
                              var msPerHour = 60 * 60 * 1000;
                              var msPerMin = 60 * 1000;
                              var msPerSec = 1000;
                              <?php echo $zeit?>
                              <?php 
                              echo $tdid?>

                              function init(){
                              <?php echo $init?>
                                  }
                                  
                              function clock(zeit,idtd){
                                   var today = new Date();   
                                   var diffMs = zeit - today.getTime();
                                   diffDays = Math.floor(diffMs / msPerDay);
                                   diffMs -= diffDays * msPerDay;
                                   diffHours = Math.floor(diffMs / msPerHour);
                                   diffMs -= diffHours * msPerHour;
                                   diffMins = Math.floor(diffMs / msPerMin);
                                   diffMs -= diffMins * msPerMin;
                                   var diffSecs = Math.floor(diffMs / msPerSec); 
                                   diffHours= ((diffHours<10)? "0" : "" ) +  (diffHours);
                                   diffMins= ((diffMins<10)? "0" : "" ) +  (diffMins);
                                   diffSecs= ((diffSecs<10)? "0" : "" ) +  (diffSecs);    
                                   document.getElementById(idtd).innerHTML=diffHours+":"+diffMins+":"+diffSecs;
                                   if(diffDays==0 && diffHours==0 && diffMins==0 && diffSecs==0){
                                   switch(idtd) {
                                   <?php echo $ende?>
                                   }
                                   }
                              }
                              // -->
                              </script>
                              </head>
                              <body onLoad="init()">
                              <?php 
                              echo $ausgabe?>
                              </body>
                              </html>
                              hast du das so gemeint?

                              Kommentar

                              Lädt...
                              X