PDA

View Full Version : Using php date as targetdate



penster1
03-02-2008, 01:26 AM
1) Script Title: Universal Countdown

2) Script URL (on DD):http://www.dynamicdrive.com/dynamicindex6/universalcountdown.htm

3) Describe problem: how to i designate a mysql data field for targetdate, in other words i have end date/time stored in mysql database and would like to have it automatically inserted into targetdate ($targettime).

Jas
03-03-2008, 01:36 AM
Try echoing the date to the call

var launchdate=new cdLocalTime("cdcontainer", "server-php", 0, "<?php echo $targettime; ?>", "debugmode")

ddadmin
03-03-2008, 01:48 AM
In general, the checklist for using any server side language to dynamically output client side JavaScripts is the same. As long as what gets output to the browser conforms to the syntax/ conventions of the client side script, as if you've manually added it to the page, it should work. In this case, it may look something like this:


var launchdate=new cdLocalTime("cdcontainer", "server-php", 0, <?echo $storedtime ?>, "debugmode")

Assuming your pages are PHP enabled (.php), and $storedtime contains the full date/ time string you wish to count down to.

ddadmin
03-03-2008, 01:49 AM
Heh what Jas said in other words.

Jas
03-03-2008, 02:08 AM
Heh what Jas said in other words.
It must be right when two people say it ;)

penster1
03-03-2008, 04:34 AM
It must be right when two people say it ;)

I have tried both of the examples that where posted prior, but neither works. Script just gives me all NAN NAN etc.

$dateclose is the timestamp from database.

$targetdate = strftime("%A, %B %d, %Y %H:%M:%S %p", $date_close);

var launchdate=new cdLocalTime("cdcontainer", "server-php", -60, "<?php echo $targetdate; ?>", "debugmode")

Any other suggestions???

ddadmin
03-03-2008, 07:47 AM
Is your page properly PHP enabled? Please post a link to the page on your site that contains the problematic script so we can check it out.

Jas
03-03-2008, 07:49 PM
In addition to having a PHP enabled server, the file also needs a .php extension (not .html) in order for it to go through the PHP parser.

I would test it by just echoing the value of the variable to the body of the page to see if it works. If it does, make sure that it conforms to the date format needed in the JavaScript.

penster1
03-04-2008, 04:47 AM
Finally resolved problem!!
Changed the following:
$targetdate = strftime("%A, %B %d, %Y %H:%M:%S %p", $date_close);

To This:
$targetdate = strftime("%B %d, %Y %H:%M:%S", $date_close);

Works Great.

Now just need the page to redirect when timesup.

Jas
03-04-2008, 05:11 PM
The script supports a function when the timer hits 0. To redirect, change:

else{ //else if target date/time met
var displaystring="" //Don't display any text
alert("Launch time!") //Instead, perform a custom alert
}
to:


else{
var displaystring="";
window.location="http://www.mysite.com";
}

penster1
03-04-2008, 08:56 PM
Thanks Jas for your help.

How do i got about calling the display function for lets say 20 items on the page that need Remaining time to show. All use the $targetdate as end date and are displayed in a table.

<td width="7%" align="right"><b><font color=<?$rcolor?><font size="2"><?=$row[pic1]?></font></td>
<td width="10%"><div id="cdcontainer" style="text-align: center;" "color:#620062;"></div></td><script type="text/javascript">
var launchdate=new cdLocalTime("cdcontainer", "server-php", -60, "<?php echo $targetdate ?>")launchdate.displaycountdown("days", formatresults2)</script>
<td width="7%" align="center"><font color="#000000" size="2">

Jas
03-04-2008, 09:32 PM
What is it your trying to do? :confused: I don't understand the question. Are you asking how to use the script 20 times on one page?

penster1
03-04-2008, 09:46 PM
I have 20 different items on the page that i want to show how much time is remaining for each item based on their expiration time. Some may be the same time, others different times. It is laid out in a table and the items information is pulled from a database, That is where i get their endtime(which is $targetdate).

Jas
03-04-2008, 09:51 PM
That's almost the same as before, but with a few modifications. See the page you got the script from-- it tells you how to call more then one. In addition to what that says, just add the time with <? echo $time; ?>.

penster1
03-04-2008, 10:48 PM
I am not quite sure how to implement the modifications, you stated. Any example would be greatly appreciated.