I have a clickable calendar, which user can select the day that they
want to view the news linking to. My calendar has the clickable event
day, but once the user click it, the day selected could not be parsed
to the mysql queries retrieval. $d has problem. How do I tackle this
$d? The code is a bit long....
<html>
<head>
<title>Calendar </title>
<body>
<form action="cal_new 1.php" method="post">
<h3>Please select month or year:</h3>
<select name="month">
<option value="1">Janua ry</option>
<option value="2">Febru ary</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">Augus t</option>
<option value="9">Septe mber</option>
<option value="10">Octo ber</option>
<option value="11">Nove mber</option>
<option value="12">Dece mber</option>
</select>
/
<select name="year">
<option value="2006">20 06</option>
<option value="2007">20 07</option>
<option value="2008">20 08</option>
<option value="2009">20 09</option>
<option value="2010">20 10</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($mont h, $year);
if (isset($_POST['d']))
{
echo "kjkljlk";
$d = $_POST['d'];
echo "d=".$d;
}
else
{
echo "183439";
$d = date("Y-n-j");
echo "d=".$d;
}
//show news and events
$show = "SELECT * FROM `bul_data` WHERE `DATE` LIKE '$d 22:36:40'";
echo "show=".$sh ow;
$showres = mysql_query($sh ow) or die(mysql_error ());
if(mysql_num_ro ws($showres)>0)
{
while ($showrow = mysql_fetch_ass oc($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 available</p>";
}
function createcal($mont h, $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=".$y ear;
}
else
{
$components = getdate();
$month = $components['mon'];
$year = $components['year'];
}
echo "month=".$month ;
echo "year=".$ye ar;
$output = "<h1>Bullet ins for $month / $year</h1>";
//create event days
$newsquery = "SELECT `DATE` FROM `bul_data`";
echo "newsquery=".$n ewsquery;
$newsres = mysql_query($ne wsquery) or die(mysql_error ());
$eventday = array();
if(mysql_num_ro ws($newsres)>0)
{
while ($newsrow = mysql_fetch_ass oc($newsres))
{
$date = $newsrow['DATE'];
echo "date=".$da te;
$eventday[] = $date;
echo "eventday=".$ev entday;
}
}
//create table tag opener and day headers
$output .="<table border=\"1\">\n ";
$output .="<tr>";
$days = array("SUN","MO N","TUE","WED", "THU","FRI","SA T");
foreach($days as $day)
{
//create calendar headers
$output .="<th><b>$da y</th>\n";
}
$output .="</tr>";
//get 1st day of month
$start = mktime(0,0,0,$m onth,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=".$maxd ay;
//$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=".$rip date;
$d = $year."-".$month."-".$counter;
echo "d=".$d;
//construct new row if 7th column is reached
if($firstweekda y == 0)
{
//$firstweekday =0;
$output .="</tr><tr>";
echo "skjsksl";
if (in_array($ripd ate, $eventday))
{
echo "2iuwiruo";
$output .="<td class=\"post\"> <a href=\"news.php ?$year-$month-
$counter\">$cou nter</a>";
$output .="<input name=\"d\" type=\"text\" 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($ripd ate, $eventday))
{
echo "sqpoipo";
$output .="<td class=\"post\"> <a href=\"news.php ?$year-$month-
$counter\">$cou nter</a>";
$output .= "<input name=\"d\" type=\"text\" type=\"hidden\" value=
\".$d.\"></td>\n";
}
else
{
echo "$%%^^&**@" ;
$output .="<td class=\"empty\" >$counter</td>\n";
}
}
$firstweekday++ ;
echo "counter=".$cou nter;
}
//$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>
want to view the news linking to. My calendar has the clickable event
day, but once the user click it, the day selected could not be parsed
to the mysql queries retrieval. $d has problem. How do I tackle this
$d? The code is a bit long....
<html>
<head>
<title>Calendar </title>
<body>
<form action="cal_new 1.php" method="post">
<h3>Please select month or year:</h3>
<select name="month">
<option value="1">Janua ry</option>
<option value="2">Febru ary</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">Augus t</option>
<option value="9">Septe mber</option>
<option value="10">Octo ber</option>
<option value="11">Nove mber</option>
<option value="12">Dece mber</option>
</select>
/
<select name="year">
<option value="2006">20 06</option>
<option value="2007">20 07</option>
<option value="2008">20 08</option>
<option value="2009">20 09</option>
<option value="2010">20 10</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($mont h, $year);
if (isset($_POST['d']))
{
echo "kjkljlk";
$d = $_POST['d'];
echo "d=".$d;
}
else
{
echo "183439";
$d = date("Y-n-j");
echo "d=".$d;
}
//show news and events
$show = "SELECT * FROM `bul_data` WHERE `DATE` LIKE '$d 22:36:40'";
echo "show=".$sh ow;
$showres = mysql_query($sh ow) or die(mysql_error ());
if(mysql_num_ro ws($showres)>0)
{
while ($showrow = mysql_fetch_ass oc($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 available</p>";
}
function createcal($mont h, $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=".$y ear;
}
else
{
$components = getdate();
$month = $components['mon'];
$year = $components['year'];
}
echo "month=".$month ;
echo "year=".$ye ar;
$output = "<h1>Bullet ins for $month / $year</h1>";
//create event days
$newsquery = "SELECT `DATE` FROM `bul_data`";
echo "newsquery=".$n ewsquery;
$newsres = mysql_query($ne wsquery) or die(mysql_error ());
$eventday = array();
if(mysql_num_ro ws($newsres)>0)
{
while ($newsrow = mysql_fetch_ass oc($newsres))
{
$date = $newsrow['DATE'];
echo "date=".$da te;
$eventday[] = $date;
echo "eventday=".$ev entday;
}
}
//create table tag opener and day headers
$output .="<table border=\"1\">\n ";
$output .="<tr>";
$days = array("SUN","MO N","TUE","WED", "THU","FRI","SA T");
foreach($days as $day)
{
//create calendar headers
$output .="<th><b>$da y</th>\n";
}
$output .="</tr>";
//get 1st day of month
$start = mktime(0,0,0,$m onth,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=".$maxd ay;
//$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=".$rip date;
$d = $year."-".$month."-".$counter;
echo "d=".$d;
//construct new row if 7th column is reached
if($firstweekda y == 0)
{
//$firstweekday =0;
$output .="</tr><tr>";
echo "skjsksl";
if (in_array($ripd ate, $eventday))
{
echo "2iuwiruo";
$output .="<td class=\"post\"> <a href=\"news.php ?$year-$month-
$counter\">$cou nter</a>";
$output .="<input name=\"d\" type=\"text\" 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($ripd ate, $eventday))
{
echo "sqpoipo";
$output .="<td class=\"post\"> <a href=\"news.php ?$year-$month-
$counter\">$cou nter</a>";
$output .= "<input name=\"d\" type=\"text\" type=\"hidden\" value=
\".$d.\"></td>\n";
}
else
{
echo "$%%^^&**@" ;
$output .="<td class=\"empty\" >$counter</td>\n";
}
}
$firstweekday++ ;
echo "counter=".$cou nter;
}
//$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>
Comment