Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11
  1. #1

    conto alla rovescia in php

    Ciao a tutti è possibile fare un conto alla rovescia come questo:
    http://scripts.franciscocharrua.com/countdown-clock.php
    che quando aggiorni riparte da dove ha iniziato?
    io dico esiste un modo per farlo e che il tempo lo prende dal database...
    Mi spiego meglio:
    se io clicco su un link del mio sito, si puo fare in modo che tramite database( io faccio una tabella con dei orari) la pagina php prenda la variabile del tempo che deve fare il conto alla rovescia(per esempio 3 ore).
    Dopo di che la pagina php se prende dal db quanto tempo deve fare il conto alla rovescia, gli resta solo piu che lavorare con il js come fa questo in questo sito ed il gioco è fatto...
    Il problema e che a parole è tutto facile, ma a fatti è complicata la cosa...
    qualcuno di voi sa come si puo fare?
    grazie per l'attenzione ciao

  2. #2
    Quello script viene richiamato così
    codice:
    <script type="text/javascript">countdown_clock(08, 12, 25, 00, 00, 1);</script>
    Quindi devi passargli anno, mese, giorno, ora e minuti

    Esattamente cosa vuoi sapere riguardante php?

  3. #3
    Ma non ho capito, la pagina in js deve essere cosi:

    Codice PHP:
    function countdown_clock(yearmonthdayhourminuteformat)
             {
             
    //I chose a div as the container for the timer, but
             //it can be an input tag inside a form, or anything
             //who's displayed content can be changed through
             //client-side scripting.
             
    html_code '<div id="countdown"></div>';
             
             
    document.write(html_code);
             
             
    countdown(yearmonthdayhourminuteformat);                
             }
             
    function 
    countdown(yearmonthdayhourminuteformat)
             {
             
    Today = new Date();
             
    Todays_Year Today.getFullYear() - 2000;
             
    Todays_Month Today.getMonth();                  
             
             
    //Convert both today's date and the target date into miliseconds.                           
             
    Todays_Date = (new Date(Todays_YearTodays_MonthToday.getDate(), 
                                     
    Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                                 
             
    Target_Date = (new Date(yearmonth 1dayhourminute00)).getTime();                  
             
             
    //Find their difference, and convert that into seconds.                  
             
    Time_Left Math.round((Target_Date Todays_Date) / 1000);
             
             if(
    Time_Left 0)
                
    Time_Left 0;
             
             switch(
    format)
                   {
                   case 
    0:
                        
    //The simplest way to display the time left.
                        
    document.all.countdown.innerHTML Time_Left ' seconds';
                        break;
                   case 
    1:
                        
    //More datailed.
                        
    days Math.floor(Time_Left / (60 60 24));
                        
    Time_Left %= (60 60 24);
                        
    hours Math.floor(Time_Left / (60 60));
                        
    Time_Left %= (60 60);
                        
    minutes Math.floor(Time_Left 60);
                        
    Time_Left %= 60;
                        
    seconds Time_Left;
                        
                        
    dps 's'hps 's'mps 's'sps 's';
                        
    //ps is short for plural suffix.
                        
    if(days == 1dps ='';
                        if(
    hours == 1hps ='';
                        if(
    minutes == 1mps ='';
                        if(
    seconds == 1sps ='';
                        
                        
    document.all.countdown.innerHTML days ' day' dps ' ';
                        
    document.all.countdown.innerHTML += hours ' hour' hps ' ';
                        
    document.all.countdown.innerHTML += minutes ' minute' mps ' and ';
                        
    document.all.countdown.innerHTML += seconds ' second' sps;
                        break;
                   default: 
                        
    document.all.countdown.innerHTML Time_Left ' seconds';
                   }
                   
             
    //Recursive call, keeps the clock ticking.
             
    setTimeout('countdown(' year ',' month ',' day ',' hour ',' minute ',' format ');'1000);
             } 

    la pagina php:
    Codice PHP:
    <?
    $sql 
    "SELECT ora FROM ore";


    <
    script type="text/javascript">countdown_clock($sql);</script>
    ?>
    è giusta questa cosa?

  4. #4
    ho cercato con google, ma non ho trovato nulla, non si puo faretutto in php?

    EDIT: ho appena trovato la versione php solo ke serve una mano per una cosa, ecco il codice:


    Codice PHP:
    function countdown_clock(year, month, day, hour, minute, format)

             {

             //I chose a div as the container for the timer, but

             //it can be an input tag inside a form, or anything

             //who's displayed content can be changed through

             //client-side scripting.

             html_code = '<div id="countdown"></div>';

             

             document.write(html_code);

             

             Today = new Date();

             Todays_Year = Today.getYear() - 2000;

             Todays_Month = Today.getMonth() + 1;

             

             <?

             $date 
    getDate();

             

             
    $second $date["seconds"];

             
    $minute $date["minutes"];

             
    $hour $date["hours"];

             
    $day $date["mday"];

             
    $month $date["mon"];

             
    $month_name $date["month"];

             
    $year $date["year"];

             
    ?>

             

             //Computes the time difference between the client computer and the server.

             Server_Date = (new Date(<?= $year 2000 ?><?= $month ?><?= $day ?>,

                                     <?= $hour ?><?= $minute ?><?= $second ?>)).getTime();

             Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(),

                                     Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();

             

             countdown(year, month, day, hour, minute, (Todays_Date - Server_Date), format);                

             }

             

    function countdown(year, month, day, hour, minute, time_difference, format)

             {

             Today = new Date();

             Todays_Year = Today.getYear() - 2000;

             Todays_Month = Today.getMonth() + 1;

                                                 

             //Convert today's date and the target date into miliseconds.

             

             Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(),

                                     Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();

             Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();

             

             //Find their difference, and convert that into seconds.

             //Taking into account the time differential between the client computer and the server.

             Time_Left = Math.round((Target_Date - Todays_Date + time_difference) / 1000);

             

             if(Time_Left < 0)

                Time_Left = 0;

             

             switch(format)

                   {

                   case 0:

                        //The simplest way to display the time left.

                        document.all.countdown.innerHTML = Time_Left + ' seconds';

                        break;

                   case 1:

                        //More datailed.

                        days = Math.floor(Time_Left / (60 * 60 * 24));

                        Time_Left %= (60 * 60 * 24);

                        hours = Math.floor(Time_Left / (60 * 60));

                        Time_Left %= (60 * 60);

                        minutes = Math.floor(Time_Left / 60);

                        Time_Left %= 60;

                        seconds = Time_Left;

                        

                        dps = 's'; hps = 's'; mps = 's'; sps = 's';

                        //ps is short for plural suffix.

                        if(days == 1) dps ='';

                        if(hours == 1) hps ='';

                        if(minutes == 1) mps ='';

                        if(seconds == 1) sps ='';

                        

                        document.all.countdown.innerHTML = days + ' day' + dps + ' ';

                        document.all.countdown.innerHTML += hours + ' hour' + hps + ' ';

                        document.all.countdown.innerHTML += minutes + ' minute' + mps + ' and ';

                        document.all.countdown.innerHTML += seconds + ' second' + sps;

                        break;

                   default: 

                        document.all.countdown.innerHTML = Time_Left + ' seconds';

                   }

                   

             //Recursive call, keeps the clock ticking.

             setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + 

                         time_difference + ', ' + format + ');', 1000);

             }
    io vorrei sapere, se tramite questo posso impostare l'orario tramite db...
    non so, avete capito cosa intendo?

  5. #5
    la pagina php:
    Codice PHP:
    <?
    $sql 
    "SELECT ora FROM ore";


    <
    script type="text/javascript">countdown_clock($sql);</script>
    ?>
    è giusta questa cosa?
    Ovviamente no, devi passare 6 variabili non una, e poi l'estrazione di dati dal db non si fa così, comunque è fattibile, nel db che tipo di dato hai?

  6. #6
    Ho cambiato idea, se tutte le date le tengo ina pagina php con un ciclo if e elseif, poi posso prenderle da li...
    il problema ora non è tanto la data da dove la prendo, è che il codice non va come vorrei io, io vorrei uno script come questo sopra ma che quanto finisce il conto alla rovescia faccia eseguire un altra pagina php...
    come si puo fare una cosa del genere?

  7. #7
    Ohhhhhhhhhhhhhhhhhhhhh
    finalmente ho trovato qualcosa che fa per me:

    Codice PHP:
    <?php
    //*****************************************************************************
    //
    // MICRO COUNTDOWN  -  Version: 1.0
    //
    // You may use this code or any modified version of it on your website.
    //
    // NO WARRANTY
    // This code is provided "as is" without warranty of any kind, either
    // expressed or implied, including, but not limited to, the implied warranties
    // of merchantability and fitness for a particular purpose. You expressly
    // acknowledge and agree that use of this code is at your own risk.
    //
    //*****************************************************************************
    ?>


    <?php
    // Define your target date here
        
    $targetYear  2007;
        
    $targetMonth 12;
        
    $targetDay   10;
        
    $targetHour  12;
        
    $targetMinute00;
        
    $targetSecond00;
    // End target date definition

    // Define date format
    $dateFormat "Y-m-d H:i:s";

    $targetDate mktime($targetHour,$targetMinute,$targetSecond,$targetMonth,$targetDay,$targetYear);
    $actualDate time();

    $secondsDiff $targetDate $actualDate;

    $remainingDay     floor($secondsDiff/60/60/24);
    $remainingHour    floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
    $remainingMinutes floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
    $remainingSeconds floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60));

    $targetDateDisplay date($dateFormat,$targetDate);
    $actualDateDisplay date($dateFormat,$actualDate);

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Max's Countdown System</title>
    <link href="style/style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
      var days = <?php echo $remainingDay?>  
      var hours = <?php echo $remainingHour?>  
      var minutes = <?php echo $remainingMinutes?>  
      var seconds = <?php echo $remainingSeconds?>  

    function setCountDown ()
    {
      seconds--;
      if (seconds < 0){
          minutes--;
          seconds = 59
      }
      if (minutes < 0){
          hours--;
          minutes = 59
      }
      if (hours < 0){
          days--;
          hours = 23
      }
      document.getElementById("remain").innerHTML = days+" days, "+hours+" hours, "+minutes+" minutes, "+seconds+" seconds";
      setTimeout ( "setCountDown()", 1000 );
    }

    </script>
    </head>

    <body onload="setCountDown();">
    <div id="container">
        <div id="header"><div id="header_left"></div>
        <div id="header_main">Max's Countdown System</div><div id="header_right"></div></div>
        <div id="content">
            <table class="countTable">
               <tr><td>Target date:</td><td><?php echo $targetDateDisplay?></td></tr>
               <tr><th colspan="2" id="remain"><?php echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes, $remainingSeconds seconds";?></th></tr>
               <tr><td>Actual date:</td><td><?php echo $actualDateDisplay?></td></tr>
           </table>
        </div>
        <div id="footer">[url="http://www.phpf1.com"]Powered by PHP F1[/url]</div>
    </div>
    </body>
    </html>
    Io vorrei sapere, come posso fare per farlo indirizzare su un altra pagina quando il conto alla rovescia arriva a 0secondi?
    diciamo quando finisce di contare...
    perfavore rispondetemi

  8. #8
    codice:
    function setCountDown ()
    {
      seconds--;
      if (seconds < 0){
          minutes--;
          seconds = 59
      }
      if (minutes < 0){
          hours--;
          minutes = 59
      }
      if (hours < 0){
          days--;
          hours = 23
      }
      
      if(seconds == 0 && minutes == 0 && hours == 0)	location.href = "http://www.html.it/";
      
      document.getElementById("remain").innerHTML = days+" days, "+hours+" hours, "+minutes+" minutes, "+seconds+" seconds";
      setTimeout ( "setCountDown()", 1000 );
    }
    Non so cosa c'entra PHP, ma tant'è

  9. #9
    grazie mille, ora quando arriva a 0 mi va in una altra pagina...
    SOlo che ce ancora un problema, se io ritorno in quella pagina, lo script non termina contina ad andare avanti, continua in negativo, non esiste un modo per farlo terminare quanto arriva a 0?

  10. #10
    up

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.