Forum Moderators: coopster

Message Too Old, No Replies

Php / SQL countdown script

php countdown script from sql server

         

adamck

9:47 am on May 27, 2008 (gmt 0)

10+ Year Member



Hi Guys,
Im a newbie here needing some help with a coundown script!
I need to have a dropdown list which a user can select:
1 day (24 hours from current time)
1 week (7 days from current date)
1 month (28 days from current date)

And then it will perform an SQL INSERT into a database with a date 1 day, week or month from now.

Then i need a seperate countdown script that grabs this expiry date and counts-down until that date.

how hard is this to do? any pointers or help is greatly appreciated!

Thanks so much for any contributions!
Adam.

wheelie34

2:00 pm on May 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi adamck and welcome to webmasterworld

In my limited knowledge I would as you say set the date into mysql I am not clear on what its counting down to though but assume its to stop someone logging in after the expirey, you can ask the login page to check current date against the mysql date to see if they still are allowed to login if not send them to the re-apply page.

It's not difficult, am I on the right track?

adamck

3:05 pm on May 27, 2008 (gmt 0)

10+ Year Member



Hi,
I am using a listing system (modified open-realty) i am wanting to make it an auction style system where the user can create a listing and select how long the listing is active for.
On the listing there will be a counter which will grab the current date, the ending date and then show time remaining for this listing.
When the timer is up the listing will expire and the counter will hide.
i managed to get this

<?php
$listingID = $_GET['listingID'];
$con = mysql_connect("localhost","****","********");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("auctionc_openr", $con);
$sql = "SELECT * FROM listing_expires WHERE (listing_id = '$listingID')";

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

$targetDateDisplay = date($dateFormat,$targetDate);
$actualDateDisplay = date($dateFormat,$actualDate);
$result =mysql_query($sql);
$row = mysql_fetch_array($result);
// Define your target date here
$targetYear = $row['year'];
$targetMonth = $row['month'];
$targetDay = $row['days'];
$targetHour = 12;
$targetMinute = 00;
$targetSecond = 00;
// End target date definition

$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);

?>
<br />
<font size="+1" color="#FF0000">Expires In: <?php echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes, $remainingSeconds seconds";?> </font> </p>

This works great but i need a dropdown box now which will have 3 selections in for 1 day, 1 week, 1 month.
When the user has selected one and submitted it will then enter a date 1 day, 7 days or 30 days from the current date into an SQl table.
Is this possible? or is there a better way around this?
Thanks
Ad.