PDA

View Full Version : Update a part of a page?



fenhopi
01-25-2011, 10:21 AM
Hi, I have this PHP code that shows the amount of minutes and seconds to a certain date. Somehow I want to update this code every second so that it looks like it's counting down. Anyone who has any good pointers how to do this?
Thank you in advance.

abduraooft
01-25-2011, 10:22 AM
Hi, I have this PHP code Where?

fenhopi
01-25-2011, 10:33 AM
date_default_timezone_set('Europe/Belgrade');
// Define date format
$dateFormat = "Y-m-d H:i:s";

$targetDateDisplay = date($dateFormat,$targetDate);
$actualDateDisplay = date($dateFormat,$actualDate);
$test = time() + 30*60;
?>

And as result here is the complete PHP code:
<br /><br /
<?php
// Define your target date here
if(isset($_POST['submit'])){
$test = time() + 30*60;
echo date('Y-m-d H:i:s', $test);
$targetYear1 = date('Y', $test);
$targetMonth1 = date('n', $test);
$targetDay1 = date('d', $test);
$targetHour1 = date('H', $test);
$targetMinute1 = date('i', $test);
$targetSecond1 = date('s', $test);
$INSERT = "INSERT INTO Blackmail (username, year, month, day, hour, minute, second) VALUES ('admin', '$targetYear1', '$targetMonth1', '$targetDay1', '$targetHour1', '$targetMinute1', '$targetSecond1')";
$Do_It = $database->query($INSERT);
}

// End target date definition
$Get_date = "SELECT * FROM Blackmail WHERE username='admin'";
$Connect = $database->query($Get_date);
$num_rows = mysql_num_rows($Connect);
if($num_rows == 0) { ?>
<form method="post" action="<? echo $PHP_SELF; ?>">
<input type="submit" name="submit" value="Black mail" />
</form><? }
while($Get = mysql_fetch_array($Connect)){

$bid = $Get['blackmailid'];
$targetYear = $Get['year'];
$targetMonth = $Get['month'];
$targetDay = $Get['day'];
$targetHour = $Get['hour'];
$targetMinute = $Get['minute'];
$targetSecond = $Get['second'];
$targetDate = mktime($targetHour,$targetMinute,$targetSecond,$targetMonth,$targetDay,$targetYear);

$actualDate = time();

$secondsDiff = $targetDate - $actualDate;



$remainingDay = floor($secondsDiff/60/60/24);
$remainingHour = floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
$remainingMinutes = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
$remainingSeconds = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60));

// Define date format
$dateFormat = "Y-m-d H:i:s";

$targetDateDisplay = date($dateFormat,$targetDate);
$actualDateDisplay = date($dateFormat,$actualDate);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<body><?

if($secondsDiff <= "0"){
echo "LEss";
$Del_Query = "DELETE FROM Blackmail WHERE blackmailid='$bid'";
$Connect_del = $database->query($Del_Query);
}
else{ ?>
TARGET DATE : <?php echo $targetDateDisplay; ?><br/><br/>
ACTUAL DATE : <?php echo $actualDateDisplay; ?><br/><br/>
REMAINING : <?php echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes, $remainingSeconds seconds"; }?>
</body>
<?
}?>