Jump to content

time php / mysql script help


lasse48

Recommended Posts

hello guys.

 

i sitting here at my pc , have used alot days on google and forums.

but i just cant seem to find what i am looking for :(

 

so i hope that anyone here got a min to tell me what to do  :wtf:

 

okai soo what i am looking for is a php / mysql script that can countdown for a user , when its finish add a number (8) to usertabel[2].

and the problem is it need to do it also if the user closes the browser.

 

i am total lost , have no ide to fix / wihte it :(

 

 

 

 

Sorry for my spelling i am danish  ::)

Link to comment
Share on other sites

you are lucky, i have created something like this just yesterday (literally yesterday)..  though you will probably have to alter it a little to fit your specific needs.

 

first off here is my switch (with only the relavent parts left in)

default:
		$date = date('Y-m-d');
		$sql = "SELECT * FROM deals WHERE start_date = '".$date."' AND status=1";
		$data = mysql_fetch_assoc(mysql_query($sql));
		putenv("TZ=US/Mountain");
		$page = 'main.tpl';
	break;

 

next we look @ my main.tpl

 

<span class="txt_body" id="count">{$data.end_date}</span>
<script>
//change the text below to reflect your own,
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d)
{
theyear=yr;themonth=m;theday=d
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[m-1]+" "+d+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
if(dday==0&&dhour==0&&dmin==0&&dsec==1)
{
document.getElementById('count').innerHTML ="expired";
return
}
else
document.getElementById('count').innerHTML="Only "+dday+ " D, "+dhour+" H, "+dmin+" M, and "+dsec+" S remaining "
setTimeout("countdown(theyear,themonth,theday)",1000)
}
//enter the count down date using the format year/month/day
var A = document.getElementById('count').innerHTML;

var myArray = A.split('-'); 
var yr = myArray['0'];
var m = myArray['1'];
var d = myArray['2'];

countdown(yr,m,d)
</script>

 

so basically, in your code you would more than likely echo out the date you want counted down..

 

hope it helps ya out.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.