Worqy Posted September 5, 2010 Share Posted September 5, 2010 Hello. Now I have made a calendar and I wan't to put in some events. The events will work like this: The user fills in a form with date, time and a message. The form data will be stored in a mysql table that looks like this: <id><date><year><time><message> Now what I need help with is this: When the user looks at the calendar I want all the dates with a event to be bold. I will do the rest myself. The code so far: <?php /* Imports */ require 'config.php'; /* Settings */ date_default_timezone_set('Europe/Helsinki'); // Get... $month = $_POST['ViewMonth']; if($month == ""){ $month = "01"; } $year= $_POST['ViewYear']; if($year == ""){ $year = "2010"; } // Check for events $con = mysql_connect("$mysql_host", "$mysql_username", "$mysql_password"); if(!$con){ echo "Error trying to connect to mysql!"; } $select_db = mysql_select_db("test"); if(!$select_db){ echo "Error trying to select mysql database!"; } $query = "SELECT FROM calendar" // Controls ?> <form action="test.php" method="POST"> Månad: <select name="ViewMonth"> <?php for($i = 1; $i < 13; $i++) { //******added for loop, so you could keep the last selected month. echo '<option '; echo ($i == (int)$month) ? 'selected="selected"' : NULL; echo '>' . $i . '</option>'; } ?> </select> År: <select name="ViewYear"> <?php for($i = 2006; $i < 2015; $i++) { //******added teh for loop, so you could keep the last selected year. echo '<option '; echo ($i == (int)$year) ? 'selected="selected"' : NULL; echo '>' . $i . '</option>'; } ?> </select> <input type="submit" value="Gå"> </form> <?php //This gets today's date $date =time () ; //This puts the day, month, and year in seperate variables $day = date('d', $date) ; //$month = date('m', $date) ; //$year = date('Y', $date) ; //Here we generate the first day of the month $first_day = mktime(0,0,0,$month, 1, $year) ; //This gets us the month name $title = date('F', $first_day) ; //*****This line had been deleted, making the switch Useless. //Here we find out what day of the week the first day of the month falls on $day_of_week = date('D', $first_day) ; $day_of_week = date('D',$first_day); //Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero switch($day_of_week){ //******days re-ordered. case "Mon": $blank = 0; break; case "Tue": $blank = 1; break; case "Wed": $blank = 2; break; case "Thu": $blank = 3; break; case "Fri": $blank = 4; break; case "Sat": $blank = 5; break; case "Sun": $blank = 6; break; } //We then determine how many days are in the current month $days_in_month = cal_days_in_month(0, $month, $year) ; //Here we start building the table heads echo "<table border=1 width=294>"; echo "<tr><th colspan=7> $title $year </th></tr>"; //*******Changed echo string to reflect that 1st day is Monday. echo "<tr><td width=42>Mån</td><td width=42>Tis</td><td width=42>Ons</td><td width=42>Tors</td><td width=42>Fre</td><td width=42>Lör</td><td width=42>Sön</td></tr>"; //This counts the days in the week, up to 7 $day_count = 1; echo "<tr>"; //first we take care of those blank days while ( $blank > 0 ) { echo "<td></td>"; $blank = $blank-1; $day_count++; } //sets the first day of the month to 1 $day_num = 1; //count up the days, untill we've done all of them in the month while ( $day_num <= $days_in_month ) { echo "<td> $day_num </td>"; $day_num++; $day_count++; //Make sure we start a new row every week if ($day_count > 7) { echo "</tr><tr>"; $day_count = 1; } } //Finaly we finish out the table with some blank details if needed while ( $day_count >1 && $day_count <=7 ) { echo "<td> </td>"; $day_count++; } echo "</tr></table>"; ?> Link to comment https://forums.phpfreaks.com/topic/212596-calendar-with-events/ Share on other sites More sharing options...
Worqy Posted September 6, 2010 Author Share Posted September 6, 2010 Anyone? I just need some help making the callender check for events for this month and this year and make the date bold. Link to comment https://forums.phpfreaks.com/topic/212596-calendar-with-events/#findComment-1107856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.