PDA

View Full Version : php calendar script... and displaying an event



Ryan
October 3rd, 2004, 07:14 PM
so yeah, i am writing a script for a very simple calendar. and when it comes to showing upcoming events, i must be retarded cause i cant get it to work. here is my code...


<style type="text/css">
<!--
.month,
.np,
.weekday,
.day,
.event,
.today{
font-size:12px;
font:Verdana, Arial, Helvetica, sans-serif;
text-align: center;
width:20;
}
.today {
background-color: #EFEFEF;
color:#990000;
border:1px solid #B5B5B5;
}
.event {
background-color: #CCFFFF;
color: #003366;
border:1px solid #B5B5B5;
}
.day {
background-color: #FFFFFF;
color:#262626;
}
-->
</style>
<?php
include"_includes/db.php";
if(!isset($month)){
$month=date("m");
}
if(!isset($year)){
$year=date("Y");
}
$fom = mktime (0,0,0, $month, 1, $year);
$maxdays = date('t', $fom);
$date_info = getdate($fom);
$month = $date_info['mon'];
$month_prev = $month-1;
$month_next = $month+1;
$month_f = $date_info['month'];
$year = $date_info['year'];
$weekday = $date_info['wday'];
$day = 1;
$day_width=20;
print"<table cellpadding=\"0\" cellspacing=\'1\"> \n";
print"<tr> \n";
print"<td class=\"np\"><a href=\"?month=$month_prev\"><!--&laquo;--></a></td> \n";
print"<th class=\"month\" colspan=\"5\">$month_f<br/>$year</th> \n";
print"<td class=\"np\"><a href=\"?month=$month_next\"><!--&raquo;--></a></td> \n";
print"</tr> \n";
print"<tr> \n";
print"<td class=\"weekday\">S</td> \n";
print"<td class=\"weekday\">M</td> \n";
print"<td class=\"weekday\">T</td> \n";
print"<td class=\"weekday\">W</td> \n";
print"<td class=\"weekday\">T</td> \n";
print"<td class=\"weekday\">F</td> \n";
print"<td class=\"weekday\">S</td> \n";
print"</tr> \n";
print"<tr> \n";
if($weekday > 0){print "<td colspan=\"$weekday\">&nbsp;</td> \n";}
$result=mysql_query("SELECT DATE_FORMAT(date,'%Y-%m-%e'),DATE_FORMAT(thrudate,'%Y-%m-%e'),event FROM dealer_events ORDER BY date");
while($row=mysql_fetch_row($result)){
while ($day <= $maxdays){
$event=$row[0];
$desc=$row[2];
$thisday="$year-$month-$day";
if($weekday == 7){
print "</tr> \n<tr> \n";
$weekday = 0;
}
if((date("Y-n-j")==$thisday)){
print "<td class=\"today\">$day</td> \n";
}elseif($event==$thisday){
print "<td class=\"event\"><acronym title=\"$desc\">$day</acronym></td> \n";
}else{
print "<td class=\"day\">$day</td> \n";
}
$day++;
$weekday++;
}
}
print"</tr> \n";
print"</table> \n";

?>

here you can view (http://candlelightcabinetry.com/dealers/calendar.php) its out come...

i know whats wrong, its the while loop where im fetching the data from the database, i just have no idea how else to get it... (as you can see form the link, only the first event in the database is displayed...) any help or direction would be more then appriciated...

thanks in advance,
~ryan

Ryan
October 4th, 2004, 08:39 AM
i am real s-m-r-t


after looking at it for a while i saw what went wrong. thanks for looking though. maybe this may help someone else in the future...

starting @ the while statement...


while ($day <= $maxdays){
$thisday="$year-$month-$day";
$result=mysql_query("SELECT DATE_FORMAT(date,'%Y-%m-%e'),DATE_FORMAT(thrudate,'%Y-%m-%e'),event FROM dealer_events WHERE date='$thisday'");
$row=mysql_fetch_row($result);
$event=$row[0];
$desc=$row[2];
if($weekday == 7){
print "</tr> \n<tr> \n";
$weekday = 0;
}
if((date("Y-n-j")==$thisday)){
print "<td class=\"today\">$day</td> \n";
}elseif($event==$thisday){
print "<td class=\"event\"><acronym title=\"$desc\">$day</acronym></td> \n";
}else{
print "<td class=\"day\">$day</td> \n";
}
$day++;
$weekday++;
}



~ryan