dooper3 Posted May 11, 2006 Share Posted May 11, 2006 Hi,I'm having trouble getting my events calendar up and running. Basically, it's for a sports club and the committee can add dates to the calendar (all works fine) and the webmaster can remove them individually (again fine), but when I want to display them, I only want to display the events that have not yet happened (and are not happening today).This is where I'm stumped, the way I want it to work is the PHP connects to a MySQL server and looks for dates that are after today's date, then chooses those events only to display but as I don't understand unix timestamps very well, I feel I am going about it the wrong way (with little success!)Another issue I want to resolve is I want it to only display the date once for the viewer if there are multiple entries with the same date.Below is my code so far...[code]<?$currentdate = mktime(0,0,0,date("j n Y"));$sql = mysql_query("SELECT * FROM calendar WHERE date<='$currentdate' ORDER BY date ASC") or die(mysql_error());$rows = mysql_numrows($sql);if ($rows == "0") { echo("<b>Nothing in the Calendar</b>");} else { while ($item = mysql_fetch_array($sql)) { extract($item); $eventdate = date("D jS F",$date); echo("<a name=\"$id\"><h4>$eventdate</h4></a><b><i>$event</i></b><br> $description<p>"); }}mysql_close();?>[/code]Thanks everyone!! Quote Link to comment https://forums.phpfreaks.com/topic/9546-displaying-only-future-dates-in-calendar/ Share on other sites More sharing options...
ryanlwh Posted May 12, 2006 Share Posted May 12, 2006 what's the data type of column `date` (DATE, DATETIME, TIMESTAMP, UNIX_TIMESTAMP)?also, your usage of mktime is incorrect. this function only take integers. you're looking for this[code]$currentdate = mktime(0,0,0,date('m'),date('d'),date('Y'));[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9546-displaying-only-future-dates-in-calendar/#findComment-35287 Share on other sites More sharing options...
Caesar Posted May 12, 2006 Share Posted May 12, 2006 Use unformatted timestamps when just dealing with the backend stuff (Queries, storing in db, comparing dates, writing conditional statements,...etc). Make life much easier for you. Only format dates for display purposes.So, what you would do to retrieve anything past today's date...you would do something extremely simple like:[code]<?php$today = time();$query_events = mysql_query("SELECT * FROM events WHERE date > '$today'");?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9546-displaying-only-future-dates-in-calendar/#findComment-35289 Share on other sites More sharing options...
ryanlwh Posted May 12, 2006 Share Posted May 12, 2006 Caesar, you've misunderstood the mktime part. time() returns the current timestamp, but it is the "current" time. If you need to get the timestamp for "today" (meaning the START of today, at 0:0 am), you have to either use mktime or the MYSQL function "CURDATE". And mktime by no means format the date. It returns a timestamp based on the given arguments.It could be an advantage to use DATE, DATETIME, and TIMESTAMP datatype in mysql, because mysql date and time functions are based on them. Also note that TIMESTAMP and UNIX_TIMESTAMP is different in mysql. TIMESTAMP has the format YYYYMMDDHHMMSS while UNIX_TIMESTAMP is the seconds since the epoch (1970). Quote Link to comment https://forums.phpfreaks.com/topic/9546-displaying-only-future-dates-in-calendar/#findComment-35297 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.