set timer in php form

how to set a timer in days, hours, minutes and seconds for countdown a

Page 1 of 1

2 Replies - 10165 Views - Last Post: 01 April 2009 - 04:08 AM Rate Topic: -----

#1 kuanhan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 31-March 09

set timer in php form

Posted 31 March 2009 - 06:53 AM

how to set a timer in days, hours, minutes and seconds for countdown an event?
if the event is finished, this section of the event and untouchable and will closed when the timer is run off..
Is This A Good Question/Topic? 0
  • +

Replies To: set timer in php form

#2 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 903
  • Joined: 08-August 08

Re: set timer in php form

Posted 31 March 2009 - 09:14 AM

you could add a timestamp into db for when the event is and then when the page is loaded yjust do that timestamp - now()

eg

set time
//10 day timer

// insert into db
$time_now = date("Y-m-d H:i:s");
//+10 days = 864000 seconds
$new_time = strtotime($time_now)+864000;
$new_timestamp = date("Y-m-D H:i:s", $newtime);
mysql_query("insert into table_name (endTime) values ($new_timestamp)");

// get time left
$event="birthday";
$dbdata = mysql_query("select endTime from table_name where event = $event");
$row = mysql_fetch_array($dbdata);
$endTime = $row['endTime'];
$endTime = strtotime($endTime);
$seconds_gap = $endTime-mktime();
$days = 0;
$hours = 0;
$minutes = 0;
$seconds = 0;
while($seconds_gap-86400 > 0){
	$seconds_gap-86400;
	$days++;
}
while($seconds_gap-3600 > 0){
	$seconds_gap-3600;
	$hours++;
}
while($seconds_gap-60 > 0){
	$seconds_gap-60;
	$minutes++;
}
while($seconds_gap-1 > 0){
	$seconds_gap-1;
	$seconds++;
}

echo $days." days, ". $hours ." hours, ". $minutes ." minutes and ". $seconds ." seconds.";



bear in mind i dont incorperate changing the plural s on the end of days hours minutes and seconds as i dont really have much time. but that is the basics of what you want i think.

you could then build in a calender and then from whatever day is selected work out the extra seconds and do the sam process i have done
Was This Post Helpful? 0
  • +
  • -

#3 kuanhan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 31-March 09

Re: set timer in php form

Posted 01 April 2009 - 04:08 AM

View Postghqwerty, on 31 Mar, 2009 - 08:14 AM, said:

you could add a timestamp into db for when the event is and then when the page is loaded yjust do that timestamp - now()

eg

set time
//10 day timer

// insert into db
$time_now = date("Y-m-d H:i:s");
//+10 days = 864000 seconds
$new_time = strtotime($time_now)+864000;
$new_timestamp = date("Y-m-D H:i:s", $newtime);
mysql_query("insert into table_name (endTime) values ($new_timestamp)");

// get time left
$event="birthday";
$dbdata = mysql_query("select endTime from table_name where event = $event");
$row = mysql_fetch_array($dbdata);
$endTime = $row['endTime'];
$endTime = strtotime($endTime);
$seconds_gap = $endTime-mktime();
$days = 0;
$hours = 0;
$minutes = 0;
$seconds = 0;
while($seconds_gap-86400 > 0){
	$seconds_gap-86400;
	$days++;
}
while($seconds_gap-3600 > 0){
	$seconds_gap-3600;
	$hours++;
}
while($seconds_gap-60 > 0){
	$seconds_gap-60;
	$minutes++;
}
while($seconds_gap-1 > 0){
	$seconds_gap-1;
	$seconds++;
}

echo $days." days, ". $hours ." hours, ". $minutes ." minutes and ". $seconds ." seconds.";



bear in mind i dont incorperate changing the plural s on the end of days hours minutes and seconds as i dont really have much time. but that is the basics of what you want i think.

you could then build in a calender and then from whatever day is selected work out the extra seconds and do the sam process i have done


thanks for ur reply,
i get your point now, but i still cant working out. i created a form which is can input the event name and the time when the event is finish. at the same time, i created a database table which call the table name is table_name(same as yours) and attributes are endTime(Type:Timestamp, default:current_timestamp) and event(type:varchar, length:50,collation:latin1_swedish_ci).


<?php

include ('config.php');
$sql="SELECT endTime FROM $tbl_name WHERE endTime='$endTime'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
$event=$rows['event'];

?>
<BR>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
  <tr>
	<form name="form1" method="post" action="Untitled-36.php">
	  <td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
		<tr>
		  <td width="18%"><strong>end time</strong></td>
		  <td width="3%">:</td>
		  <td width="79%"><input name="endTime" type="text" id="endTime" size="45"></td>
		</tr>
		  <tr>
		  <td>&nbsp;</td>
		  <td><input name="id" type="hidden" value="<? echo $endTime; ?>"></td>
		  <td><input type="submit" name="Submit" value="Submit">
			<input type="reset" name="Submit2" value="Reset"></td>
		</tr>
	  </table></td>
	</form>
  </tr>
</table>


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1