Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Need help with an alarm clock in javascript with MYSQL background

    Thanks for clicking on the link and i presume while you are here on my thread yo u will try to help me
    So here is the situation. I am building webpage that displays a clock , a ticker box and a countdown(alarm clock). I have found many previously coded alarm clocks/countdown timers but they dont do what i need. Then what do you need you might be asking yourself?! - I need a countdown timer with background in MySQL database(there will be multiple events in that database) and then checks which is the next one( Alarms will be in HH:MM format so they can be activated every day), after the check it displays a countdown(logical eh?) until that event - when it reaches that event it should redirect to some other site(which will return user to the same site after 15 min pause) and then All over again, check which is next, countdown , redirect , AGAIN
    This website is designed not to be clicked or anything - it should work by itself.
    Are YOU able to help me? (Just a fair warning - Im a newb in javascript so dont be too harsh on me)

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    Ok, usually we are not a cheap coding service. You should ask specific questions about code (or code segments) that you have already implemented and that you're still having problems with.

    I think there is another forum section on CF where you can find someone for hire.

  • #3
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    im sorry but i didnt expect you to be a cheap coding service... i was hoping that you could tell me if it can be done and give me some guidince. I found precoded countdown timers but they all realy on a exact date and time While my program needs to work every day and sound the alarm ( redirection ) every time that countdown reches a certain event. Im a bit puzzled how to connect MYSQL database with javascript- can the times be compared or i have to do some kind of conversion?
    here is the example of how the program should work :
    Lets say that we have it on some machine connected to a big screen.
    On the screen there is a big clock . Underneeth is a cooldown. We start at 7 AM
    At 9 AM there is a first event - i need the countdown to 9 AM , at 9 AM it redirects to a second site where there is a countdown from 15 min mark... After that coundown is back to 0 it redirects back to our first site where it finds the next event 11 AM and counts down to it. and so on for the whole day. Problem is how do i compare the times and how do i get javascript to count down to that point - not to some predefined(precoded) date and time.

  • #4
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    Ok, some hints

    1. You cannot connect client side Javascript to (server side) MySQL databases
    2. You'll need a server side script / program (like PHP) to access the MySQL database
    3. You can send a request to this server side script and receive the results (output) of the script
    4. You can use the normal browser URL bar to access the server side script, you can use HTML forms to call the script and you can use so-called AJAX techniques to access the script
    5. The output format is mostly TXT ... but you can output almost anything you want. Just make sure that you can cope with the output in Javascript
    6. This means: You can output the MySQL date/time as whatever you want ... maybe even as "17:59" in 24 hrs format ...
    7. In Javascript you can calculate the time difference until the next event and start an interval of (let's say) 200 msec. After each interval, update the countdown timer on screen

    At this point I don't understand your specific requirements. Are you talking about several events that will lead to several parallel countdowns on the user's screen? Or is it just one event at a time (the next one) and as soon as this is finished, check the next event?

  • Users who have thanked devnull69 for this post:

    iGoogle (03-02-2012)

  • #5
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you - that explained allot, and that is just the kind of help i needed!
    I get around php and MySQL so it wont be a problem collecting data from MySQL.
    JavaScript is a new language for me so i think there will be a problem there



    It is just one event at a time (the next one) and as soon as this is finished, check the next event.

    This should be something like an info panel. I already made ticker box at the bottom ( that wasnt too complex - allot of pre-coded tickers on the web). but i wasn't able to find that cooldown that shows exact time from now to a variable.

  • #6
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    Counting down from now to a later time today will not be a problem. A pitfall will be if the destination time is less than the current time so the event will be tomorrow.

    Code:
    var dest = "07:59";
    var hours = parseInt(dest.substring(0, 2), 10);
    var mins = parseInt(dest.substring(3), 10);
    var destDate = new Date();
    var now = new Date();
    destDate.setHours(hours);
    destDate.setMinutes(mins);
    if(now>destDate) destDate.setTime(destDate.getTime() + 24*60*60*1000); // add 1 day
    
    var diff = destDate - now;
    var hourstogo = Math.floor(diff/(60*60*1000));
    diff = diff - hourstogo*60*60*1000;
    var minstogo = Math.floor(diff/(60*1000));
    alert(hourstogo + " hours, " + minstogo + " minutes to go");

  • Users who have thanked devnull69 for this post:

    iGoogle (03-07-2012)

  • #7
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks alot! that helped. I had to modify it a bit but it worked ( still didn't menage to pull seconds out of it but hey.. not a priority ) .
    I have another problem now... i decided to put 2 tickers (scrolling texts in the file - found some scroling text js files and included them but when i try to make 2 scroling texts they dont show. When i try to display only one it shows... And i really dont have any idea what to do...

    Code:
    <DIV ID="TICKER1" STYLE="overflow:hidden; width:1500px">
    test
    
    <script type="text/javascript" src="webticker_lib1.js" language="javascript"></script>
    </DIV>
    <DIV ID="TICKER" STYLE="overflow:hidden; width:1500px">
    <?php echo $nesto ?>
    <script type="text/javascript" src="webticker_lib.js" language="javascript"></script>
    </DIV>
    You have any clue whats wrong?


  •  

    Posting Permissions

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