RE: [PHP] calendar Q

From: Date: Fri, 11 Aug 2006 13:40:39 +0000
Subject: RE: [PHP] calendar Q
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-240543@lists.php.net to get a copy of this message
I like using mktime() whenever I pull dates from a database. Get your date from the query, store it to a value: $val = mktime($qval); Then you can compare any part of the date you want by using date(). if( date( "m", date(now)) == date( "m", $val )) m = month Jef -----Original Message----- From: William Stokes [mailto:kalles@operamail.com] Sent: Thursday, August 10, 2006 11:23 PM To: php-general@lists.php.net Subject: Re: [PHP] calendar Q Ok. Thanks. One more question. I have dates as a datetime in DB. Like 2006-08-11 08:20:00 and I'm playing only with date part in the calendar 2006-08-11. So how to compare this date to the datetime info in DB? Do I need to use DATE_FORMAT or someting like this in the query? Thanks -Will ""Richard Lynch"" <ceo@l-i-e.com> kirjoitti viestissä:2821.67.108.68.40.1155241480.squirrel@www.l-i-e.com... > On Thu, August 10, 2006 12:14 pm, William Stokes wrote: >> I have a calendar script that displays a simple mini calendar view one >> month >> at a time. User can click any date and the calendar opens another page >> that >> displays that date's events. I would like to highlight to the mini >> calendar >> view dates that have an event in database. So what would be a simple >> way to >> check for events while the selected months days are printed to screen? > > Depending on the number of records, the PHP<->MySQL connection speed, > and the indexes or lack thereof on your date column... > > 1. You could do a query for each date like: > select count(*) from events where whatdate = '$date' > > 2. You could pre-fill an array with dates that have an event: > select whatdate from events > where whatdate >= '$month/1/$year' > and whatdate < '{$month+1}/1/$year' /*might need something better here*/ > group by whatdate > order by whatdate > while (list($whatdate) = mysql_fetch_row($result)){ > $event_date[$whatdate] = true; > } > Then, while filling out the calendar, just check: > if (isset($event_date[$date])){ > //color it as having events > } > > -- > Like Music? > http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#240543) next »