Forum Moderators: coopster
i have a mysql database that contains dates and events, i want to put these into a php calendar script i made in a tutorial. the problem is I am not really sure how to go about it. I know that i have to come up with a script that will read the month/year selected, then compare the dates to the dates in the database, but i'm not a programmer and am not sure where to start. below is the script i have to create the calendar. Any help would be appriciated.
<?php
define("ADAY", (60*60*24));
if (!checkdate($_POST['month'], 1, $_POST['year'])) {
$nowArray = getdate();
$month = $nowArray['mon'];
$year = $nowArray['year'];
} else {
$month = $_POST['month'];
$year = $_POST['year'];
}
$start = mktime (12, 0, 0, $month, 1, $year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title><?php echo "Calendar:".$firstDayArray['month']."
17: ".$firstDayArray['year']?></title>
<head>
<body>
<form method="post" action="<?php echo "$_SERVER[PHP_SELF]";?>">
<select name="month">
<?php
$months = Array("January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December");
for ($x=1; $x <= count($months); $x++) {
echo"<option value=\"$x\"";
if ($x == $month) {
echo " SELECTED";
}
echo ">".$months[$x-1]."";
}
?>
</select>
<select name="year">
<?php
for ($x=2008; $x<=2010; $x++) {
echo "<option";
if ($x == $year) {
echo " SELECTED";
}
echo ">$x";
}
?>
</select>
<input type="submit" value="Go!">
</form>
<br>
<?php
$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<TABLE BORDER=1 WIDTH=750 CELLPADDING=20><tr>\n";
foreach ($days as $day) {
echo "<TD BGCOLOR=\"#CCCCCC\" ALIGN=CENTER><strong>$day</strong></td>\n";
}
for ($count=0; $count < (6*7); $count++) {
$dayArray = getdate($start);
if (($count % 7) == 0) {
if ($dayArray['mon']!= $month) {
break;
} else {
echo "</tr><tr>\n";
}
}
if ($count < $firstDayArray['wday'] ¦¦ $dayArray['mon']!= $month) {
echo "<td> </td>\n";
} else {
echo "<td>".$dayArray['mday']." </td>\n";
$start += ADAY;
}
}
echo "</tr></table>";
?>
</body>
</html>
I understand how the above script works.. just need to populate it with my DB. any suggestions on where to start?
`id` int(11) NOT NULL auto_increment,
`f_name` varchar(25) NOT NULL default '',
`l_name` varchar(35) NOT NULL default '',
`address_line_1` varchar(50) NOT NULL default '',
`address_line_2` varchar(50) NOT NULL default '',
`state` char(2) NOT NULL default '',
`city` varchar(35) NOT NULL default '',
`zipcode` varchar(5) NOT NULL default '',
`date` varchar(10) NOT NULL default '',
`caption` varchar(250) NOT NULL default '',
PRIMARY KEY (`id`)
date holds the date, and caption is the event i want to display on the calendar
Thanks
The PHP Forum Library [webmasterworld.com] has a thread that describes the Basics of extracting data from MySQL [webmasterworld.com]. Have a look at the code, develop your query and see if you are getting the information returned from the query as you expect. Once past that stage, you can begin to incorporate how to get that data into your HTML display.