Results 1 to 6 of 6

Thread: Live Countdown From Database?

  1. #1
    Join Date
    Apr 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Live Countdown From Database?

    Is it possible to do a live countdown from a database?

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You could, but depending on what you mean by "live", I could give a different answer. In other words, by "live" do you mean you want it to automatically update every second, minute, etc or do you want something else? Have you looked in the library for a countdown script (made in javascript) that you could modify for your needs? In any case, if you want a more specific answer, we need a more specific question.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Apr 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Sorry for not giving more explanation.

    The script i have will put not allow a user to do certain things for a set time. The script will then put the user's "username" and a certain "time" (depending what was done) in the database.

    EXAMPLE: (whats inserted)

    id|username|time_left
    1| joejoe20 | 120
    ------------------------

    I would like to show on a page this information

    Username | Time Left
    -------------------------
    joejoe20 | 2:00

    Then i would like it to countdown to zero.

    Hopefully i made more sense. I looked at javascript and i was told javascript wouldnt be able to interact with mysql. (i never scripted javascript)

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You could modify this script to do what you want.

    http://www.dynamicdrive.com/dynamici...lcountdown.htm

    Simply use php to write the date to countdown to (based on the time pulled from the db) and insert it into the cdLocalTime function. I would go into more detail, but I'm short on time at the moment.

    Hope this helps nonetheless.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. The Following User Says Thank You to thetestingsite For This Useful Post:

    joejoe20 (04-17-2008)

  6. #5
    Join Date
    Apr 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thank You

    Im sorry if im asking to much. I have never played around with javascript, i have no clue how to have javascript call a php command to find how much time is left.

  7. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Well, after following the instructions on DD, simply make your PHP script connect to the database, get the time left, add that number to the seconds returned by the time() function, then output that date to the JavaScript. Something like the following should suffice as a basis to what I'm talking about (Not tested).

    Code:
    <?php
     include('db_connect.php'); //connect to the db
    ?>
    <table>
     <tr>
      <td>Username</td>
      <td>Time Left</td>
     </tr>
     $result = mysql_query("SELECT * FROM `table` WHERE `username`='$username'");
     while ($row = mysql_fetch_array($result)) {
       $futuredate = date('F d, Y H:i:s', time()+$row['time_left']);
    ?>
     <tr>
      <td><?php echo $row['username'];?></td>
      <td><div id="cdcontainer"></div>
    
    <script type="text/javascript">
    //cdLocalTime("ID_of_DIV_container", "server_mode", LocaltimeoffsetMinutes, "target_date", "opt_debug_mode")
    //cdLocalTime.displaycountdown("base_unit", formatfunction_reference)
    
    //Note: "launchdate" should be an arbitrary but unique variable for each instance of a countdown on your page:
    
    var launchdate=new cdLocalTime("cdcontainer", "server-php", 0, "<?php echo $futuredate;?>", "debugmode")
    launchdate.displaycountdown("days", formatresults2)
    </script></td>
     </tr>
    <?php
     }
    ?>
    </table>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •