caine Posted December 16, 2006 Share Posted December 16, 2006 I want to work on news calendar, for which users can select months and year that they want before linking them to the news event on the specified date. However, my calendar is not working. Hanging when I compile. May I know wad's the problem? [code]<?php//function generatecal($monthname,$year,$datearray)//{define("aday", (60*60*24)); //get 1st day of month $start = mktime(0,0,0,$monthname,1,$year); //get month $day1 = getdate($start); $components = getdate(); //get name of month $monthname = $components['mon']; //get name of year $year = $components['year']; ?>//provide selection functions<form action="<? echo $PHP_SELF ?>" method="post"><select name ="month"> //months selection <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option></select><select name="year"> //years selection <option value="2006">2006</option> <option value="2007">2007</option> <option value="2008">2008</option> <option value="2009">2009</option> <option value="2010">2010</option> </select><input type ="submit" value = "Submit"></form><p><?php $days = array("SUN","MON","TUE","WED","THU","FRI","SAT"); //create table tag opener and day headers $calendar = "<table>\n"; foreach($days as $day) //create calendar headers $calendar .= "\t<td><strong>$day</strong></td>\n"; $date_today = getdate($start); //get days of week $weekdays = $components[wday]; //calculate number of days in the current month $daysnum = cal_days_in_month(0,$monthname,$year); $daynow = 1; if ($weekdays > 0) { $calendar .= "\t<td><br></td>\n"; } while ($daynow <= $daysnum) { //construct new row when 7th column is reached if($weekdays == 7) { $weekdays = 0; $calendar .= "</tr><tr>\n"; } //check if $daynow is a member of $datearray if (in_array($daynow,$datearray)) { //link to the day $date = "$year-$monthname-$daynow"; $calendar .= "<td><a href='dates.php?$date'>$daynow</a></td>"; } //$daynow is not a member of $datearray else { $calendar .= "\t<td>$date_today[wday]</td>\n"; $start += aday; } $daynow++; $weekdays++; if ($weekdays != 7) { $calendar .= "<td colspan='.(7 - $weekdays).'><br></td>\n"; }}$calendar .= "</tr></table>";echo $calendar;//return $calendar;//}?>[/code] Quote Link to comment Share on other sites More sharing options...
caine Posted December 16, 2006 Author Share Posted December 16, 2006 I missed out the events calling part, which is essential for initializing the $datearray. Here it is:[code]<html><head><title>Bulletin Selections</title></head><body><?php $db = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("bulletin", $db) or die(mysql_error()); $display = "<h1>News for $date</h1>"; //year month are selected to generate calendar if(isset($_POST['yearmonth'])) { $year = substr($getyearmonth, 0, 4); $month = substr($getyearmonth, 5, 2); } //if no year month are selected, return current year and month by default else { $components = getdate(); $month = $components['mon']; $year = $components['year']; } $date = "$year-$month"; $query = "SELECT * FROM `bul_data` WHERE `DATE` LIKE '$date%'"; $res = mysql_query($query) or die(mysql_error()); if(mysql_numrows($res) > 0) { echo "<table width=\"100%\" border=\"1\">"; echo "<tr>"; echo "<th>Title</th>"; echo "<th>Department</th>"; echo "<th>Link</th>"; echo "</tr>"; while ($newsrow=mysql_fetch_assoc($newsres)) { $pubdate = substr($newsrow['DATE'], 0, 10); $datearray[] = $pubdate; $title = $row['TITLE']; $department = $row['DEPARTMENT']; $campus = $row['CAMPUS']; $link = $row['LINK']; $display .= "<tr> <td><strong>$title</strong></td> <td>$department</td> <td>$link</td> </tr>"; } $display .="</table>"; } else { $display .= "No news available."; } echo $display; echo generatecal($month, $year,$datearray); ?></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
caine Posted December 16, 2006 Author Share Posted December 16, 2006 There's no errors statement. When I debugged, my calendar doesn't work. Hopefully anybody can help with this. Quote Link to comment Share on other sites More sharing options...
caine Posted December 26, 2006 Author Share Posted December 26, 2006 My calendar can fill the current month with the correct numbering of weekdays. However, I want to complete the day blanks with previous month and next month weekdays, then shade them with different colors. How do I do that?I had modified my calendar into the following:[code]<html><head><title>Calendar</title><body><form action="cal_new1.php" method="post"><h3>Please select month or year:</h3><select name="month"> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option></select> /<select name="year"> <option value="2006">2006</option> <option value="2007">2007</option> <option value="2008">2008</option> <option value="2009">2009</option> <option value="2010">2010</option></select><input type="submit" value="Display Calendar" /></form><?php //Initialize variables import_request_variables('pgc', ''); //if neither month nor year is selected, display current year and month calendar if (empty($month)) { $components = getdate(); $month = $components['month']; $year = $components['year']; } echo "month=".$month; echo "year=".$year; echo "<h1>Bulletins for $month / $year</h1>"; //create table tag opener and day headers echo "<table border=\"1\">\n"; echo "<tr>"; $days = array("SUN","MON","TUE","WED","THU","FRI","SAT"); foreach($days as $day){ //create calendar headers echo "<th><b>$day</th>\n";} echo "</tr>"; //get 1st day of month $start = mktime(0,0,0,$month,1,$year); echo "start=".$start; $thisdate = getdate($start); $firstweekday = $thisdate['wday']; //$firstweekday = jddayofweek(gregoriantojd($month,1,$year,0)); echo "firstweekday=".$firstweekday; //$next_month = getDate(mktime(0, 0, 0, $month + 1, 1, $year)); //echo "next_month=".$next_month; echo "<tr>"; //align first week of month for($cday = 0; $cday<$firstweekday; $cday++) { echo "<td> </td>\n"; } //calculate number of days in the current month //$maxday = cal_days_in_month(CAL_GREGORIAN,$month,$year); //$maxday = round(($next_month[0] - $thisdate[0]) / (60 * 60 * 24)); $maxday = date('t', $start); echo "maxday=".$maxday; //display days of remaining weeks for($counter = 1; $counter<=$maxday; $counter++) { $firstweekday %= 7; //construct new row if 7th column is reached if($firstweekday == 0) { //$firstweekday =0; echo "</tr><tr><td><a href=\"news.php?$year-$month-$counter\">$counter</a></td>\n"; } //not yet reach last column, continue to display else { echo "<td><a href=\"news.php?$year-$month-$counter\">$counter</a></td>\n"; } $firstweekday++; } //$restday = getdate(mktime(0, 0, 0, $month, $maxday, $year)); //for ($cday = $restday+1; $cday < 7; $cday++) //{ // echo "<td> </td>"; //} ?> </tr> </table></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
bljepp69 Posted December 26, 2006 Share Posted December 26, 2006 There are two excellent calendar tutorials here - [url=http://www.phpfreaks.com/tutorial_cat/29/Calendars--Date-&-Time.php]http://www.phpfreaks.com/tutorial_cat/29/Calendars--Date-&-Time.php[/url]. I know at least one of them covers the questions you are asking. Quote Link to comment Share on other sites More sharing options...
caine Posted January 13, 2007 Author Share Posted January 13, 2007 I had entered eventdays so that the day will be linked when news is available. However, I got this error.Parse error: parse error in C:\Program Files\xampp\htdocs\cal_new1.php on line 178 for this part:if (in_array($counter, $eventday){ $output .="<td><a href=\"news.php?$yearname-$monthname-$counter\">$counter</a></td>\n";}What could be the problem?[code]<html><head><title>Calendar</title><body><form action="cal_new1.php" method="post"><h3>Please select month or year:</h3><select name="month"> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option></select> /<select name="year"> <option value="2006">2006</option> <option value="2007">2007</option> <option value="2008">2008</option> <option value="2009">2009</option> <option value="2010">2010</option></select><input type="submit" value="Display Calendar" /></form><?php $db = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("bulletin", $db) or die(mysql_error()); //get year & month from the calendar if((!empty($_POST['month'])) and (!empty($_POST['year']))) { $monthname = $_POST['month']; echo "monthname".$monthname; $yearname = $_POST['year']; echo "yearname".$yearname; } //generate event calendar echo createcal($monthname, $yearname); //show news and events $show = "SELECT * FROM `bul_data` WHERE `DATE` LIKE '$yearname-$monthname%'"; echo "show=".$show; $showres = mysql_query($show) or die(mysql_error()); if(mysql_num_rows($showres)>0) { while ($showrow = mysql_fetch_assoc($showres)) { $day = $showrow['DATE']; $title = $showrow['TITLE']; $department = $showrow['DEPARTMENT']; $campus = $showrow['CAMPUS']; $link = $showrow['LINK']; echo "<p>$day</p>\n"; echo "<p>$title</p>\n"; echo "<p>$department</p>\n"; echo "<p>$campus</p>\n"; echo "<p>$link</p>\n"; } } else { echo "<p>No news today</p>"; } function createcal($monthname, $yearname){ //Initialize variables import_request_variables('pgc', ''); //if neither month nor year is selected, display current year and month calendar if (empty($month)) { $components = getdate(); $month = $components['month']; $year = $components['year']; } echo "month=".$month; echo "year=".$year; $output = "<h1>Bulletins for $month / $year</h1>"; $newsquery = "SELECT `DATE` FROM `bul_data`"; $newsres = mysql_query($newsquery) or die(mysql_error()); if(mysql_num_rows($res)>0) { while ($newsrow = mysql_fetch_assoc($newsres)) { $date = $newsrow['DATE']; $eventday[] = $date; echo "eventday=".$eventday; } } //create table tag opener and day headers $output .="<table border=\"1\">\n"; $output .="<tr>"; $days = array("SUN","MON","TUE","WED","THU","FRI","SAT"); foreach($days as $day){ //create calendar headers $output .="<th><b>$day</th>\n";} $output .="</tr>"; //get 1st day of month $start = mktime(0,0,0,$month,1,$year); echo "start=".$start; $thisdate = getdate($start); $firstweekday = $thisdate['wday']; //$firstweekday = jddayofweek(gregoriantojd($month,1,$year,0)); echo "firstweekday=".$firstweekday; //$next_month = getDate(mktime(0, 0, 0, $month + 1, 1, $year)); //echo "next_month=".$next_month; $output .="<tr>"; //align first week of month for($cday = 0; $cday<$firstweekday; $cday++) { $output .="<td> </td>\n"; } //calculate number of days in the current month //$maxday = cal_days_in_month(CAL_GREGORIAN,$month,$year); //$maxday = round(($next_month[0] - $thisdate[0]) / (60 * 60 * 24)); $maxday = date('t', $start); echo "maxday=".$maxday; //display days of remaining weeks for($counter = 1; $counter <= $maxday; $counter++) { $firstweekday %= 7; //construct new row if 7th column is reached if($firstweekday == 0) { //$firstweekday =0; $output .="</tr><tr>"; if (in_array($counter, $eventday) { $output .="<td><a href=\"news.php?$yearname-$monthname-$counter\">$counter</a></td>\n"; } else { $output .="<td>$counter</td>\n"; } } //not yet reach last column, continue to display else { if (in_array($counter, $eventday) { $output .="<td><a href=\"news.php?$yearname-$monthname-$counter\">$counter</a></td>\n"; } else { $output .="<td>$counter</td>\n"; } } $firstweekday++; } $restday = getdate(mktime(0, 0, 0, $month, $maxday, $year)); for ($cday = $restday+1; $cday < 7; $cday++) { $output .="<td> </td>"; } $output .="</tr>"; $output .="</table>";return $output;}</body></html>[/code] Quote Link to comment Share on other sites More sharing options...
Barand Posted January 13, 2007 Share Posted January 13, 2007 Changeif (in_array($counter, $eventday)toif (in_array($counter, $eventday) ) Quote Link to comment Share on other sites More sharing options...
caine Posted January 14, 2007 Author Share Posted January 14, 2007 Ok. My calendar has the display. But it could not take in the input of month and year, therefore the calendar only displays current month and year calendar. Besides, there's no event days which are linked(hyperlink activated, i mean). What could be the problem again? Quote Link to comment Share on other sites More sharing options...
Barand Posted January 14, 2007 Share Posted January 14, 2007 Your arguments for the createCal() function are $monthname and $yearname yet you begin the function by checking if $month is empty. Quote Link to comment Share on other sites More sharing options...
caine Posted January 18, 2007 Author Share Posted January 18, 2007 I had solved the clickable problem. But after I selected the day, which variable should I link to my news db? Quote Link to comment Share on other sites More sharing options...
caine Posted January 22, 2007 Author Share Posted January 22, 2007 Having the clickable day on my calendar, I store the clickable day into $d. However, when I clicked the day, it will refresh current page and suppose to show the news based on the selected. But it is not. The $d is actually failed to capture the values of the clickable day selected. It just got the current day , month and year. How do I tackle this?[code]<html><head><title>Calendar</title><body><form action="cal_new1.php" method="post"><h3>Please select month or year:</h3><select name="month"> <option value="01">January</option> <option value="02">February</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> <option value="06">June</option> <option value="07">July</option> <option value="08">August</option> <option value="09">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option></select> /<select name="year"> <option value="2006">2006</option> <option value="2007">2007</option> <option value="2008">2008</option> <option value="2009">2009</option> <option value="2010">2010</option></select><input type="submit" value="Display Calendar" /><?php $db = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("bulletin", $db) or die(mysql_error()); //generate event calendar echo createcal($month, $year); if (isset($_POST['d'])) { echo "kjkljlk"; $d = $_POST['d']; echo "d=".$d; } else { echo "183439"; $d = date("Y-m-d"); echo "d=".$d; } //show news and events $show = "SELECT * FROM `bul_data` WHERE `DATE` LIKE '$d 22:36:40'"; echo "show=".$show; $showres = mysql_query($show) or die(mysql_error()); if(mysql_num_rows($showres)>0) { while ($showrow = mysql_fetch_assoc($showres)) { $day = $showrow['DATE']; $title = $showrow['TITLE']; $department = $showrow['DEPARTMENT']; $campus = $showrow['CAMPUS']; $link = $showrow['LINK']; echo "<p>$day</p>\n"; echo "<p>$title</p>\n"; echo "<p>$department</p>\n"; echo "<p>$campus</p>\n"; echo "<p><a href=\"$link\">$link</a></p>\n"; } } else { echo "<p>No news today</p>"; } function createcal($month, $year){ $month = ""; $year = ""; //get year & month from the calendar if (isset($_POST['month']) && isset($_POST['year'])) { $month = $_POST['month']; echo "post_month=".$month; $year = $_POST['year']; echo "post_year=".$year; } else { $components = getdate(); $month = $components['mon']; $year = $components['year']; } echo "month=".$month; echo "year=".$year; $output = "<h1>Bulletins for $month / $year</h1>"; //create event days $newsquery = "SELECT `DATE` FROM `bul_data`"; echo "newsquery=".$newsquery; $newsres = mysql_query($newsquery) or die(mysql_error()); $eventday = array(); if(mysql_num_rows($newsres)>0) { while ($newsrow = mysql_fetch_assoc($newsres)) { $date = $newsrow['DATE']; echo "date=".$date; $eventday[] = $date; echo "eventday=".$eventday; } } //create table tag opener and day headers $output .="<table border=\"1\">\n"; $output .="<tr>"; $days = array("SUN","MON","TUE","WED","THU","FRI","SAT"); foreach($days as $day){ //create calendar headers $output .="<th><b>$day</th>\n";} $output .="</tr>"; //get 1st day of month $start = mktime(0,0,0,$month,1,$year); echo "start=".$start; $thisdate = getdate($start); $firstweekday = $thisdate['wday']; echo "firstweekday=".$firstweekday; //calculate number of days in the current month $maxday = date('t', $start); echo "maxday=".$maxday; //$next_month = getDate(mktime(0, 0, 0, $month + 1, 1, $year)); //echo "next_month=".$next_month; $output .="<tr>"; //align first week of month for($cday = 0; $cday < $firstweekday; $cday++) { $output .="<td> </td>\n"; } //display days of remaining weeks for($counter = 1; $counter <= $maxday; $counter++) { $firstweekday %= 7; $ripdate = "$year-$month-$counter 22:36:40"; echo "ripdate=".$ripdate; echo "d=".$d; //construct new row if 7th column is reached if($firstweekday == 0) { //$firstweekday =0; $output .="</tr><tr>"; echo "skjsksl"; if (in_array($ripdate, $eventday)) { echo "2iuwiruo"; $output .="<td class=\"post\"><a href=\"?$year-$month-$counter\">$counter</a>"; $d = $year."-".$month."-".$counter; echo "d=".$d; $output .= "<input name='d' type='hidden' value=".$d."></td>\n"; } else { echo "qoiwwo"; $output .="<td class=\"empty\">$counter</td>\n"; } } //not yet reach last column, continue to display else { if (in_array($ripdate, $eventday)) { echo "sqpoipo"; $output .="<td class=\"post\"><a href=\"?$year-$month-$counter\">$counter</a>"; $d = $year."-".$month."-".$counter; echo "d=".$d; $output .= "<input name='d' type='hidden' value=".$d."></td>\n"; } else { echo "qoqp][pq]"; $output .="<td class=\"empty\">$counter</td>\n"; } } $firstweekday++; echo "counter=".$counter; } //$restday = getdate(mktime(0, 0, 0, $month, $maxday, $year)); //for ($cday = $restday+1; $cday < 7; $cday++) //{ // $output .="<td> </td>"; //} $output .="</tr>"; $output .="</table>"; $output .="</form>";return $output;}?></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
caine Posted January 23, 2007 Author Share Posted January 23, 2007 This part i added in:if (isset($_POST['d'])){echo "kjkljlk";$d = $_POST['d'];echo "d=".$d;}else{echo "183439";$d = date("Y-m-d");echo "d=".$d;}//show news and events$show = "SELECT * FROM `bul_data` WHERE `DATE` LIKE '$d 22:36:40'";echo "show=".$show;But it doesn't able to show db queries after clicking the $d for these:if (in_array($ripdate, $eventday)){echo "2iuwiruo";$output .="<td class=\"post\"><a href=\"?$year-$month-$counter\">$counter</a>";$d = $year."-".$month."-".$counter;echo "d=".$d;$output .= "<input name='d' type='hidden' value=".$d."></td>\n";}else{echo "qoiwwo";$output .="<td class=\"empty\">$counter</td>\n";} Quote Link to comment 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.