View Full Version : Need help with an alarm clock in javascript with MYSQL background

02-29-2012, 10:55 AM
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)

02-29-2012, 01:05 PM
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.

02-29-2012, 01:43 PM
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.

02-29-2012, 03:22 PM
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?

03-02-2012, 08:41 AM
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 :D

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.

03-02-2012, 09:49 AM
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.

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();
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");

03-07-2012, 02:47 PM
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...

<DIV ID="TICKER1" STYLE="overflow:hidden; width:1500px">

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