0

Hey guys,

I need a little help with some code im working on.
In the end I want some code to change the visible text when dates are past, my current code is below, but this only works for one date. I would like it to update to the next date in a calendar when the date passes.

date_default_timezone_set('Europe/London');

$nextEvent = "2012-06-23 21:00:00";
$dateEventAfterNext = "30th June 2012";
$dateNextEvent = "23rd June 2012";

if( strtotime($nextEvent) < time() ){ // date format is YYYY-MM-DD
echo $dateEventAfterNext;
}else{   
echo $dateNextEvent;
}

Any ideas guys?

Thanks

2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by diafol
0

Does this have to be real-time or can it just work on page load. What I mean is, should the changes occur as you're watching the screen or can they be set when the page is first rendered, and you only see the difference when the page is reloaded?

0

Let me rephrase the question.

Im trying to display the date of the next event.
When this date passes, it moves onto the next date etc.

For example, if today is the 23rd June, and the next event is on the 26th June, on the 26th June at 21:00 the date of the next event will be shown.

At the moment, I just have this code that works for one week, and will require me to change the $nextevent date. Im looking for some method of inputting the dates into a MySQL table for example, and then the php reading that information onto the page.

<?php

$nextEvent = "2012-06-23 21:00:00";

if( strtotime($nextEvent) < time() ){
//when date has past
}else{
//when date hasnt past
}

?>

Any Ideas?

Thanks

0

Save dates to mysql - you need help on that?
Should be straightforward:

$result = mysql_query("INSERT INTO table (...) VALUES (...)");

Retrieving the latest event - if you're changing on 21:00:

$today = date('Y-m-d');
$op = (date('H:i') >= '21:00') ? ">" : ">=";
$result = mysql_query("SELECT ... FROM table WHERE mydate $op '$today' ORDER BY mydate LIMIT 1"); 
//then use mysql_num_rows and mysql_fetch_assoc

EDIT
Sorry, just re-read your post - saw the date format:

$time = date("Y-m-d H:i:s);
$result = mysql_query("SELECT ... FROM table WHERE mydate > '$time' ORDER BY mydate LIMIT 1");

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.