I have been stuck for days trying to figure out the best method to go about doing what I need done. I have a json url that I am pulling data from that is in an array like below. The date range can be a month to a full years worth of data. I need to do a check if tickets are soldout or not. If soldout equals true it should display soldout on that date in the calendar. If soldout equals false it should display the $url variable in the date in the calendar that matches the date in start.
Array format I am trying to work with
array(3) {
[0]=> object(stdClass)#1 (4) {
["id"]=> string(3) "165"
["start"]=> string(18) "05/02/2020 1:00 PM"
["title"]=> string(19) "Event 1:00 PM"
["alldetails"]=> array(1) {
[0]=> object(stdClass)#2 (1) {
["soldout"]=> bool(false)
}
}
}
[1]=> object(stdClass)#3 (4) {
["id"]=> string(3) "166"
["start"]=> string(18) "07/19/2020 5:00 PM"
["title"]=> string(19) "Event 5:00 PM"
["alldetails"]=> array(1) {
[0]=> object(stdClass)#4 (1) {
["soldout"]=> bool(false)
}
}
}
[2]=> object(stdClass)#5 (4) {
["id"]=> string(3) "167"
["start"]=> string(18) "11/14/2020 9:00 PM"
["title"]=> string(19) "Event 1:00 PM"
["alldetails"]=> array(1) {
[0]=> object(stdClass)#6 (1) {
["soldout"]=> bool(false)
}
}
}
}
Pulling data from json array
<?php
$array = 'https://URL/feed.json?start=2020-05-02&end=2020-11-14';
$obj = json_decode(file_get_contents($array));
foreach ($obj as $key => $value){
$id = $value->id;
$start = $value->start;
$title = $value->title;
$url = ''.$title.'';
$details = $value->alldetails;
foreach($details as $nested){
$nested->soldout; //Outputs 1 or is blank
}
}
?>
Someone else's calendar I have been attempting to insert data into. Not sure if I should use this or try my hand at building my own. Not very good with date formatting in PHP Long way to learn and a lot of refreshers needed.
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<table>
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" cellspacing="0" cellpadding="0" border="1">
<tr>
<td width="50%" align="left">Previous</td>
<td width="50%" align="right">Next</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" cellpadding="2" cellspacing="2" border="1">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<th><strong>S</strong></th>
<th><strong>M</strong></th>
<th><strong>T</strong></th>
<th><strong>W</strong></th>
<th><strong>T</strong></th>
<th><strong>F</strong></th>
<th><strong>S</strong></th>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ) echo "<tr>";
if($i < $startday) echo "<td></td>";
else echo "<td align='center' valign='middle' height='20px'>". ($i - $startday + 1) . "</td>";
if(($i % 7) == 6 ) echo "</tr>";
}
?>
</table>
</td>
</tr>
</table>
So to break it down once again, I need to insert $url into the calendar where start date matches the calendars correct date but only if not soldout. If soldout equals true then it should probably just echo "SoldOut"; or leave blank, something to that nature. Any help getting on the right track to get the information in the calendar would be great.
Give this a go and let me know if it's what you want.
I've created an array that holds all the events for the specified date range. Then, when the calendar is being populated, it checks if the current day is in the array. If so, it displays whether it's available or sold out.
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<table>
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" cellspacing="0" cellpadding="0" border="1">
<tr>
<td width="50%" align="left" onclick="changeDate(<?php echo $prev_month .','. $prev_year; ?>);" style="color:#FFFFFF">Previous</a></td>
<td width="50%" align="right" onclick="changeDate(<?php echo $next_month .','. $next_year; ?>);" style="color:#FFFFFF">Next</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" cellpadding="2" cellspacing="2" border="1">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<th><strong>S</strong></th>
<th><strong>M</strong></th>
<th><strong>T</strong></th>
<th><strong>W</strong></th>
<th><strong>T</strong></th>
<th><strong>F</strong></th>
<th><strong>S</strong></th>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
$eventsArray = array();
$array = 'https://URL/feed.json?start='.$cYear.'-'.$cMonth.'-'.$startday.'&end='.$cYear.'-'.$cMonth.'-'.$maxday;
$obj = json_decode(file_get_contents($array));
foreach ($obj as $key => $value) {
$id = $value->id;
$start = $value->start;
$title = $value->title;
$url = ''.$title.'';
$details = $value->alldetails;
$date = new DateTime($value->start);
$day = $date->format('d');
foreach($details as $nested){
$soldOut = $nested->soldout;
array_push($eventsArray, array($day, $soldOut));
}
}
for ($i=0; $i<($maxday+$startday); $i++) {
$currentDay = $i - $startday + 1;
if($i % 7 == 0) {
echo "<tr>";
}
if($i < $startday) {
echo "<td></td>";
}else{
// Check if current day is in array $currentEvents
foreach($eventsArray as $event){
if($event[0] == $currentDay) {
if($event[1] == 1) { // event is soldout
echo "<td align='center' valign='middle' height='20px'><p>".$currentDay."</p><p>Soldout</p></td>";
}else{
echo "<td align='center' valign='middle' height='20px'><p>".$currentDay."</p><p>Available</p></td>";
}
}else{
echo "<td align='center' valign='middle' height='20px'><p>".$currentDay."</p><p>No Event</p></td>";
}
}
}
if($i % 7 == 6) {
echo "</tr>";
}
}
?>
</table>
</td>
</tr>
</table>
I was helped a great deal by #El_Vanja, Taught me a great deal about creating a function that would do exactly what I was looking for. Seems I was going about things the wrong way and he guided me to find the correct answer helping along the way as much as he could while still teaching me to do it myself. Kudos to #Il_Vanja, would make a great PHP teacher.
Here is the working code, Still needs cleaned up a great bit including the if statements for displaying the events but as is it works as expected.
<?php
$array = 'https://feed.json?start=2020-01-01&end=2100-12-31';
$obj = json_decode(file_get_contents($array,true));
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<table>
<tr align="center">
<td>
<table width="100%" cellspacing="0" cellpadding="0" border="1">
<tr>
<td width="50%" align="left"><div class="m_buttons"><a href="<?php echo "?month=". $prev_month . "&year=" . $prev_year; ?>" ><strong>Previous Month</strong></a></div></td>
<td width="50%" align="right"><div class="m_buttons"><a href="<?php echo "?month=". $next_month . "&year=" . $next_year; ?>" ><strong>Next Month</strong></a></div></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" cellpadding="2" cellspacing="2" border="1">
<tr align="center">
<td colspan="7"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<th><strong>Sun</strong></th>
<th><strong>Mon</strong></th>
<th><strong>Tues</strong></th>
<th><strong>Wed</strong></th>
<th><strong>Thurs</strong></th>
<th><strong>Fri</strong></th>
<th><strong>Sat</strong></th>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
function getDateCellContent(array $obj, $d) {
$f_newdate = DateTime::createFromFormat('Y-m-j', $d);
$f_newdate = $f_newdate->format('m/d/Y');
$cellLink = '';
$cellSoldout = '';
foreach ($obj as $key => $value) {
$start = $value->start;
$a_newdate = DateTime::createFromFormat('m/d/Y g:i A', $start);
$a_date = $a_newdate->format('m/d/Y');
$a_time = $a_newdate->format('g:i A');
$id = $value->id;
$title = $value->title;
if($a_date === $f_newdate) {
foreach ($value->alldetails as $details) {
$name = $details->name;
$title = $value->title;
$link1 = '<div class="link1"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link2 = '<div class="link2"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link3 = '<div class="link3"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link4 = '<div class="link4"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link5 = '<div class="link5"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link6 = '<div class="link6"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link7 = '<div class="link7"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link8 = '<div class="link8"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link9 = '<div class="link9"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link10 = '<div class="link10"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link11 = '<div class="link11"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
if (!$details->soldout && $title === "Event 1:00 PM") {
$cellLink .= $link1;
}
if (!$details->soldout && $title === "Event 10:00 AM") {
$cellLink .= $link2;
}
if (!$details->soldout && $title === "Event 2:30 PM") {
$cellLink .= $link3;
}
if (!$details->soldout && $title === "Mother's Day Event 1:00 PM") {
$cellLink .= $link4;
}
if (!$details->soldout && $title === "Sunset Event 6:00 PM") {
$cellLink .= $link5;
}
if (!$details->soldout && $title === "Spring Event 10:00 AM") {
$cellLink .= $link6;
}
if (!$details->soldout && $title === "All Day Event 10:00 AM") {
$cellLink .= $link7;
}
if (!$details->soldout && $title === "Winter Event 3:00 PM") {
$cellLink .= $link8;
}
if (!$details->soldout && $title === "Winter Event 5:00 PM") {
$cellLink .= $link9;
}
if (!$details->soldout && $title === "Winter Event 7:00 PM") {
$cellLink .= $link10;
}
if (!$details->soldout && $title === "Father's Day Event 1:00 PM") {
$cellLink .= $link11;
}else{
}
}
}
}
return $cellLink . $cellSoldout;
}
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ) echo "<tr>";
if($i < $startday) echo "<td></td>";
else echo "<td align='center' valign='middle' height='20px'>".($i - $startday + 1) ."<br />". getDateCellContent($obj, $cYear.'-'.$cMonth.'-'.($i - $startday + 1)) ."</td>";
if(($i % 7) == 6 ) echo "</tr>";
}
?>
</table>
</td>
</tr>
</table>
Related
After receiving help below #rx2347 everything is working the way it should except one things. I have edited my question to better explain the issue.
I have an json array and I am pulling certain data such as 'id' and 'start' start displays a date and time together. I am comparing the date with the calendars date and trying to insert the correct time in the correct date. Kind of like a matching game.
Currently everything works however inserting is only inserting the very last value in the array and I need it to insert every value. Getting stuck below is what I have now after the help from #rx2347
<?php
$url = 'JSON ARRAY';
$data = file_get_contents($url);
$array = json_decode($data, true);
foreach($array as $your_json_date) {
//convert date and time
$your_date = strftime("%G%m%d", strtotime($your_json_date["start"]));
$your_time = strftime("%I:%M %P",strtotime($your_json_date["start"]));
$your_id = $your_json_date["id"];
$result = ''.$your_time.'';
}
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<table width="200">
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" cellspacing="0" cellpadding="0" border="1">
<tr>
<td width="50%" align="left">Previous</td>
<td width="50%" align="right">Next</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" cellpadding="2" cellspacing="2" border="1">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<th><strong>S</strong></th>
<th><strong>M</strong></th>
<th><strong>T</strong></th>
<th><strong>W</strong></th>
<th><strong>T</strong></th>
<th><strong>F</strong></th>
<th><strong>S</strong></th>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
for ($i=0; $i<($maxday+$startday); $i++) {
// compare your date and calendar date
$thisdate = strftime("%G%m%d",strtotime($cMonth."/".($i - $startday + 1)."/".$cYear));
if($your_date == $thisdate) $time = $result; else $time = "";
if(($i % 7) == 0 ) echo "<tr>";
if($i < $startday) echo "<td></td>";
else {
echo "<td align='center' valign='middle' height='20px'>";
echo ($i - $startday + 1);
//output time
echo "<br><b>".$time."</b>";
echo "</td>";
}
if(($i % 7) == 6 ) echo "</tr>";
}
?>
</table>
</td>
</tr>
</table>
So, all you need to know is how to compare those two dates, right?
First: Convert both dates to the same format using strtotime and strftime
$date = "05/02/2020 1:00 PM";
echo strftime("%G%m%d",strtotime($date));
This will convert your JSON date to "20200502", no matter what time. Do the same with your PHP date from your calendar and check if they are equal. Done.
I hope I understood you correctly.
This is the altered code:
<?php
//your json date
$your_json_date = "05/02/2020 1:00 PM";
//convert date and time
$your_date = strftime("%G%m%d", strtotime($your_json_date));
$your_time = strftime("%I:%M %P",strtotime($your_json_date));
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<table width="200">
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" cellspacing="0" cellpadding="0" border="1">
<tr>
<td width="50%" align="left">Previous</td>
<td width="50%" align="right">Next</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" cellpadding="2" cellspacing="2" border="1">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<th><strong>S</strong></th>
<th><strong>M</strong></th>
<th><strong>T</strong></th>
<th><strong>W</strong></th>
<th><strong>T</strong></th>
<th><strong>F</strong></th>
<th><strong>S</strong></th>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
for ($i=0; $i<($maxday+$startday); $i++) {
// compare your date and calendar date
$thisdate = strftime("%G%m%d",strtotime($cMonth."/".($i - $startday + 1)."/".$cYear));
if($your_date == $thisdate) $time = $your_time; else $time = "";
if(($i % 7) == 0 ) echo "<tr>";
if($i < $startday) echo "<td></td>";
else {
echo "<td align='center' valign='middle' height='20px'>";
echo ($i - $startday + 1);
//output time
echo "<br><b>".$time."</b>";
echo "</td>";
}
if(($i % 7) == 6 ) echo "</tr>";
}
?>
</table>
</td>
</tr>
</table>
Check the linked PHP docs for further changes.
I have this script. The code below shows the usual calendar
<table cellspacing="0" cellpadding="0" border="0" width="100%" class="view-calendar">
<tr>
<td valign="top" width="14.2857%">Monday</td>
<td valign="top" width="14.2857%">Tuesday</td>
<td valign="top" width="14.2857%">Wednesday</td>
<td valign="top" width="14.2857%">Thursday</td>
<td valign="top" width="14.2857%">Friday</td>
<td valign="top" width="14.2857%">Saturday</td>
<td valign="top" width="14.2857%">Sunday</td>
</tr>
<?php
date_default_timezone_set('Asia/Jakarta');
$days_count = date('t');
$current_day = date('d');
// save time of first day for later use
$time_first_day_of_month = mktime(0, 0, 0, date('m'), 1, date('Y'));
$week_day_first = date('N', $time_first_day_of_month);
// Get next month dates
$next_start = strtotime(date("Y-m-00", strtotime("+1 month")));
$next_dates = array();
for ($w = 1 - $week_day_first + 1; $w <= $days_count; $w = $w + 7){
echo '<tr>';
$counter = 0;
for ($d = $w; $d <= $w + 6; $d++){
if($d < 10){
$current_date = date("Y").date("m").'0'.$d;
}else{
$current_date = date("Y").date("m").$d;
}
echo '<td valign="top" width="14.2857%"'.(($d > 0 ? ($d > $days_count ? ' class="disabled"' : '') : ' class="disabled"')).(($counter > 4 ? ' class="week-day"' : '')).'>';
if($d > 0){
// next month's dates
if($d > $days_count){
for($in = 1; $in <= 1; $in++){
echo array_push($next_dates, date('j', strtotime("+ $in day", $next_start)));
}
}
// today
else if($current_day == $d){
echo '<div class="current-day" style="font-weight: bold;color:red;"><span class="given-date">'.$d.'</span></div>';
}
// this month's dates
else{
echo '<span class="given-date">'.$d.'</span>';
}
}
// last month's dates
else{
//Here comes previous dates
$offset = $d - 1;
echo '<span class="given-date">'.date('d', strtotime("$offset day",$time_first_day_of_month)).'</span>';
}
echo '</td>';
$counter++;
}
echo '</tr>';
}
?>
</table>
I want to create an Islamic calendar like this https://www.islamicfinder.org/islamic-calendar/. How to combine it with islamic calendar? And I do not know how to calculate to get the calendar result of Islam
I am creating an events calendar for my website and I have used this tutorial and this other one, as well as the youtube tutorial by unknown ghost.
However, when I enter an event, it comes up as successful but doesn't turn blue.
Have I made an error/typo that could explain why it isn't turning blue?
Also once an event has been added, it does display at the bottom but if I refresh the page the event gets added again automatically.
Went through each month and realised February doesn't come up. Why is this?
Here is my code:
calendar.php
<?php
include("functions.php")
?>
<html>
<head>
<title>Event Calendar</title>
<script>
function goLastMonth(month, year){
if(month == 1) {
--year;
month = 13;
}
--month
var monthstring = ""+month+"";
var monthlength = monthstring.length;
if(monthlength <=1){
monthstring = "0"+monthstring;
}
document.location.href = "<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year;
}
function goNextMonth(month, year){
if(month == 12) {
++year;
month = 0;
}
++month
var monthstring = ""+month+"";
var monthlength = monthstring.length;
if(monthlength <=1){
monthstring = "0"+monthstring;
}
document.location.href = "<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year;
}
</script>
<style>
.today{
background-color: #00ff00;
}
.event{
background-color: #0000ff;
}
</style>
</head>
<body>
<?php
//get current date or specific month and year
if (isset($_GET['day'])){
$day = $_GET['day'];
} else {
$day = date("d");
}
if(isset($_GET['month'])){
$month = $_GET['month'];
} else {
$month = date("m");
}
if(isset($_GET['year'])){
$year = $_GET['year'];
}else{
$year = date("Y");
}
//get date data for display such as month name
$currentTimeStamp = strtotime( "$day-$month-$year");
$monthName = date("F", $currentTimeStamp);
//get the number of days in the current month and year
$numDays = date("t", $currentTimeStamp);
//keep track of the number of cell created
$counter = 0;
?>
<?php
if(isset($_GET['add'])) {
$name = $_POST['Event_Name'];
$details = $_POST['Details'];
$date = $day."/".$month."/".$year;
$location = $_POST['Location'];
$staffrq = $_POST['Staff_Required'];
$cadetsrq = $_POST['Cadets_Required'];
//insert into database
$sqlinsert = "INSERT INTO Event_Detail (Event_Name, Details, Date, Location, Staff_Required, Cadets_Required) VALUES
('".$name."', '".$details."', '".$date."', '".$location."', '".$staffrq."','".$cadetsrq."')";
$resultinsert = mysql_query($sqlinsert);
if($resultinsert) {
echo "Event Successfully Added...";
}else{
echo "Event Failed to be Added...";
}
}
?>
<table border="1px">
<tr>
<td align="center">
<input style='width:80px;' type='button' value='<'name='previousbutton' onclick ="goLastMonth(<?php echo $month.','.$year?>)">
</td>
<td align="center" colspan="5"><?php echo $monthName." ".$year; ?></td>
<td align="center">
<input style='width:80px;' type='button' value='>'name='nextbutton' onclick ="goNextMonth(<?php echo $month.','.$year?>)">
</td>
</tr>
<tr>
<td align="center" width='80px'>Monday</td>
<td align="center" width='80px'>Tuesday</td>
<td align="center" width='80px'>Wednesday</td>
<td align="center" width='80px'>Thursday</td>
<td align="center" width='80px'>Friday</td>
<td align="center" width='80px'>Saturday</td>
<td align="center" width='80px'>Sunday</td>
</tr>
<tr align="center">
<?php
for($i = 1; $i < $numDays+1; $i++, $counter++){
$timeStamp = strtotime("$i-$month-$year");
//create empty cell until first day of the month
if($i == 1) {
//0=sun, 1=mon, 2=tue, ...
$firstDay = date("w", $timeStamp);
//if sunday change the firstDay to 7
if($firstDay == 0)
$firstDay = 7;
//decrement firstDay by 1
$firstDay--;
for($j = 0; $j < $firstDay; $j++, $counter++) {
echo "<td> </td>";
}
}
//create new row
if($counter % 7 == 0) {
echo"</tr><tr>";
}
$monthstring = $month;
$monthlength = strlen($monthstring);
$daystring = $i;
$daylength = strlen($daystring);
if($monthlength <=1){
$monthstring = "0".$monthstring;
}
if($daylength <=1) {
$daystring = "0".$daystring;
}
$todaysDate = date("d/m/Y");
$dateToCompare = $daystring.'/'.$monthstring.'/'.$year;
//print day number
echo "<td align='center'";
if ($todaysDate == $dateToCompare) {
echo "class='today'";
}else{
$sqlCount = "SELECT * FROM Event_Detail WHERE Date='".$dateToCompare."'";
$noOfEvent = mysql_num_rows(mysql_query($sqlCount));
if($noOfEvents >=1) {
echo "class='event'";
}
}
echo "><a href='".$_SERVER['PHP_SELF']."?day=".$daystring."&month=".$monthstring."&year=".$year."&v=true'>".$i."</a></td>";
}
//fill up the leftover cells of the table
while($counter % 7 != 0) {
echo "<td> </td>";
$counter++;
}
?>
</tr>
</table>
<?php
if(isset($_GET['v'])){
echo "<a href='".$_SERVER['PHP_SELF']."?day=".$day."&month=".$month."&year=".$year."&v=true&f=true'>Add Event</a>";
if(isset($_GET['f'])){
include("eventform.php");
}
$sqlEvent = "SELECT * FROM Event_Detail WHERE Date='".$day."/".$month."/".$year."'";
$resultEvents=mysql_query($sqlEvent);
echo "<hr>";
while($events=mysql_fetch_array($resultEvents)){
echo "Event Name: ".$events['Event_Name']."<br>";
echo "Details: ".$events['Details']."<br>";
echo "Date: ".$events['Date']."<br>";
echo "Location: ".$events['Location']."<br>";
echo "Staff Required: ".$events['Staff_Required']."<br>";
echo "Cadets Required: ".$events['Cadets_Required']."<br>";
}
}
?>
</body>
</html>
eventform.php
<title>Event</title>
<form name="eventform" method="POST" action="<?php $_SERVER['PHP_SELF']; ? >?day=<?php echo $day;?>&month=<?php echo $month;?>&year=<?php echo $year;? >&v=true&add=true">
<table width="400px">
<tr>
<td width="150px">Event Name</td>
<td width="250px"><input type="text" name="Event_Name" required></td>
</tr>
<tr>
<td width="150px">Details</td>
<td width="250px"><textarea name="Details" required></textarea></td>
</tr>
<tr>
<td width='150px'>Location</td>
<td width='250px'><textarea name="Location" required></textarea></td>
</tr>
<tr>
<td width='150px'>Staff Required</td>
<td width='250px'><input type='number' name="Staff_Required" required></td>
</tr>
<tr>
<td width='150px'>Cadets Required</td>
<td width='50px'><input type='number' name="Cadets_Required" required></td>
</tr>
<tr>
<td colspan='2' align='center'><input type='submit' name='btnadd' value='Add Event'></td>
</tr>
I have php to display the calender and another php to check database to see bookings, If there is a booking on certain day it displays "Booked". In database i have column for date of booking and title. How could i make it to display Title from the database instead of "Booked"?
This is to display calender.
<?php
$monthNames = Array("January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December");
?>
<?php
if (!isset($_REQUEST["month"]))
$_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"]))
$_REQUEST["year"] = date("Y");
?>
<?php
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 )
{
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 )
{
$next_month = 1;
$next_year = $cYear + 1;
}
require("BookingsDB.php");
$myBookingsDB = new BookingsDB();
$bookings = $myBookingsDB->getMonthlyBookings($cMonth,$cYear);
?>
<div align="left">
<table width="400" border="5" align="left" id="calendar">
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF"><table width="100%" border="0"
cellspacing="0" cellpadding="0">
<tr>
<td width="50%" align="left"><a href="<?php echo $_SERVER["PHP_SELF"]
. "?month=". $prev_month . "&year=" . $prev_year; ?>"
style="color:#FFFFFF">Previous</a></td>
<td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"]
. "?month=". $next_month . "&year=" . $next_year; ?>"
style="color:#FFFFFF">Next</a></td>
</tr>
</table></td>
</tr>
<tr>
<td align="center"><table width="100%" border="2" cellpadding="2"
cellspacing="2">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong> <?php
echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">
<strong>S</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">
<strong>M</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">
<strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">
<strong>W</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">
<strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">
<strong>F</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">
<strong>S</strong></td>
</tr>
<?php
require("connection.php");
$con=mysqli_connect("$mysql_host","$mysql_user","$mysql_password","$mysql_database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql= "select activityEvent.activityTitle from activityEvent";
$result = mysqli_query($con,$sql);
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
$today = getdate();
for ($i=0; $i<($maxday+$startday); $i++)
{
if(($i % 7) == 0 )
{
echo "<tr> ";
}
if($i < $startday)
{
echo "<td></td> ";
}
else
{
$day = $i - $startday + 1;
$thisDate = new DateTime("$cYear-$cMonth-$day");
$jsEvent[] = "document.getElementById('trigger" . $i . "').onclick = function() {showForm()};";
echo "<td align='center' valign='middle' height='20px'><a href='#' id='trigger" . $i . "'>". ($i - $startday + 1) . "</a>";
foreach ($bookings as $bookingDate)
{
if ($thisDate==$bookingDate)
{
echo "Booked";
while($row = mysqli_fetch_array($result))
{
echo $sql= "select activityEvent.activityTitle from activityEvent";
}
}
}
echo "</td>";
}
if(($i % 7) == 6 )
{
echo "</tr> ";
}
}
mysqli_close($con);
?>
<script type="text/javascript">
<?php foreach($jsEvent as $event)
{
echo $event;
}
?>
function showForm(){
document.getElementById('timeslots').style.display="block";
};
</script>
</table></td>
</tr>
</table>
This PHP checks booked dates in the database.
<?php
class BookingsDB
{
private $bookings = array();
private $con;
public function BookingsDB()
{
require("connection.php");
$this->con = mysqli_connect($mysql_host,$mysql_user,$mysql_password,$mysql_database);
}
public function getMonthlyBookings($thisMonth,$thisYear)
{
$sql = "SELECT date,activityTitle FROM activityEvent WHERE YEAR(date) = $thisYear AND MONTH(date) = $thisMonth";
$result = mysqli_query($this->con,$sql);
while($row=mysqli_fetch_array($result))
{
$thisBooking = $row['date'];
$thisBookingDateTime = new DateTime($thisBooking);
array_push($this->bookings,$thisBookingDateTime);
}
return $this->bookings;
}
public function close()
{
mysqli_close($this->con);
}
}
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
.red
{
color: red
}
.green
{
background-color: aquamarine;
}
table
{
text-align: center;
}
td
{
height: 60px;
width: 100px;
}
.opcity
{
background-color: rgba(0,0,0,.2);
}
</style>
</head>
<body>
<?php
$Cur_day = date('d');
$Cur_Month = date('m');
$Cur_Year = date('Y');
$op = '';
if (isset($_REQUEST['month']) || isset($_REQUEST['year']) && isset($_REQUEST['stday']))
{
$Mo = $_REQUEST['month'];
$Year = $_REQUEST['year'];
$query_date = $Year . '-' . $Mo . '-21';
if (isset($_REQUEST['opra']))
{
$str = $_REQUEST['opra'];
if ($str == 'iny')
{
$op = '+1 year';
}
if ($str == 'dey')
{
$op = '-1 year';
}
if ($str == 'inm')
{
$op = '+1 month';
}
if ($str == 'dem')
{
$op = '-1 month';
}
if ($str == 'dem' || $str == 'inm' || $str == 'dey' || $str == 'iny')
{
$query_date1 = date('Y-m-01', strtotime($op, strtotime($query_date)));
$lastDay = date('t', strtotime($op, strtotime($query_date)));
$year = date('Y', strtotime($op, strtotime($query_date)));
$month = date('n', strtotime($op, strtotime($query_date)));
$Month_Name = date('M', strtotime($op, strtotime($query_date)));
$pre_month = date('t', strtotime('-1 month', strtotime($year . '-' . $month . '-21')));
}
if ($str == 'No')
{
$query_date1 = date('Y-m-01', strtotime($query_date));
$lastDay = date('t', strtotime($query_date));
$year = date('Y', strtotime($query_date));
$month = date('n', strtotime($query_date));
$Month_Name = date('M', strtotime($query_date));
$pre_month = date('t', strtotime('-1 month', strtotime($year . '-' . $month . '-21')));
}
}
?>
<input type="hidden" name="txt_year" id="txt_year1" value="<?php echo $year; ?>">
<input type="hidden" name="txt_month1" id="txt_month1" value="<?php echo $month; ?>">
<table border="1">
<tr>
<td><<</td>
<td><</td>
<td colspan="3"><?php echo $Month_Name . "-" . $year; ?></td>
<td>></td>
<td>>></td>
</tr>
<tr>
<?php
echo '<tr>';
for ($i = 1; $i <= 7; $i++)
{
if ($_REQUEST['stday'] == 'Sun')
{
$j_val = 0;
echo "<th>" . date("l", gmmktime(0, 0, 0, 11, $i, 2015));
echo '</th>';
} else
{
$j_val = 1;
echo "<th>" . date("l", gmmktime(0, 0, 0, 6, $i, 2015));
echo '</th>';
}
}
echo '</tr>';
?>
</tr>
<?php
$Conn = new mysqli("localhost", "root", "", "demo");
$firstDays = mktime(0, 0, 0, date($month), 1, date($year));
$weekday = date('N', $firstDays);
$i = 0;
$j = 0;
$date = 1;
$Count = 0;
$Count1 = 0;
$next_mo = 1;
function Holiday($day1, $month1, $year1)
{
global $Conn;
$result = $Conn->query("SELECT * FROM holiday");
while ($row = mysqli_fetch_assoc($result))
{
if ($row['day'] == $day1 && $row['month'] == $month1 && $row['year'] == $year1)
{
return $row['title'] . "<br>";
}
}
}
for ($i = 0; $i < 6; $i++)
{
echo '<tr>';
$pre_month = $pre_month - ($weekday - $j_val);
for ($j = $j_val; $j <= 6 + $j_val; $j++)
{
if ($Count < $weekday - $j_val && ($weekday != 7 || $_REQUEST['stday'] == 'Mon'))
{
echo "<td class='opcity'>" . ( ++$pre_month) . "</td>";
$Count++;
} else
{
if ($date <= $lastDay)
{
if ($Cur_day == $date && $Cur_Month == $month && $Cur_Year == $year)
{
if (date("l", gmmktime(0, 0, 0, $month, $date, $year)) == 'Sunday')
{
echo '<td class = "green red">';
echo Holiday($date, $month, $year);
} else
{
echo '<td class = "green">';
echo Holiday($date, $month, $year);
}
} else
{
if (date("l", gmmktime(0, 0, 0, $month, $date, $year)) == 'Sunday')
{
echo '<td class = "red">';
echo Holiday($date, $month, $year);
} else
{
echo '<td >';
echo Holiday($date, $month, $year);
}
}
echo $date;
echo '</td>';
$date++;
if ($date == $lastDay)
{
$i = 7;
}
} else
{
echo "<td class='opcity'>" . $next_mo++ . "</td>";
}
}
}
echo '</tr>';
}
}
?>
</table>
</body>
</html>
//<Ajax_cal.php
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="JS/jquery-1.11.3.min.js" type="text/javascript"></script>
<script>
function Caleonload()
{
$('#month').val('<?php echo date("n"); ?>');
$('#year').val('<?php echo date('Y'); ?>');
Opretion('No');
}
function Cal(month)
{
$('#month').val(month);
Opretion('No');
}
function Cal1(year)
{
$('#year').val(year);
Opretion('No');
}
function Opretion(Op)
{
var st_day = $('input[type="radio"][class="rd_sun_mon"]:checked').val();
var Mo = $('#month').val();
var Year = $('#year').val();
var Op1 = Op;
$.post("AJAX/Ajax_Cal.php",
{
month: Mo,
year: Year,
opra: Op1,
stday: st_day
},
function (data)
{
$('#Show_Cal').html(data);
var txt_year = $('#txt_year1').val();
$("#year").html('');
for (var y = parseInt(txt_year) - 5; y < parseInt(txt_year) + 5; y++)
{
$("#year").append('<option value="' + y + '">' + y + '</option>');
}
$('#year').val(txt_year);
$('#month').val($('#txt_month1').val());
}
);
}
function incyear()
{
Opretion('iny');
}
function deyear()
{
Opretion('dey');
}
function incmonth()
{
Opretion('inm');
}
function demonth()
{
Opretion('dem');
}
</script>
</head>
<body onload="Caleonload()">
<select name="month" id="month" onchange="Cal(this.value)" size="1">
<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" id="year" onchange="Cal1(this.value)" size="1">
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
</select>
Starting Day :
<input type="radio" name="rd_sun_mon" class="rd_sun_mon" value="Sun" checked="" onchange="Opretion('No')">Sunday
<input type="radio" name="rd_sun_mon" class="rd_sun_mon" value="Mon" onchange="Opretion('No')">Monday
<div id="Show_Cal"></div>
</body>
</html>
DATA BASE PHP MY ADDMIN:
CREATE TABLE IF NOT EXISTS holiday (
id int(5) NOT NULL AUTO_INCREMENT,
day int(4) NOT NULL,
month int(4) NOT NULL,
year int(6) NOT NULL,
title varchar(20) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
I think your problem is that is that you need to put the format in order to compare two Datetime :
if ($thisDate->format('Y-m-d')==$bookingDate->format('Y-m-d'))
{
echo "Booked";
....
}
In addition to #SimonGuichard's answer, I suggest that you return an associative array from the getMonthlyBookings function that contains both the date and the activityTitle. This way, you wouldn't have to select the title from the database again when it needs to be displayed.
public function getMonthlyBookings($thisMonth,$thisYear) {
$sql = "SELECT date,activityTitle FROM activityEvent WHERE YEAR(date) = $thisYear AND MONTH(date) = $thisMonth";
$result = mysqli_query($this->con,$sql);
while($row=mysqli_fetch_array($result)) {
$this->bookings[] = array('date'=>new DateTime($row['date']), 'activityTitle'=>$row['activityTitle']);
}
return $this->bookings;
}
Then in the script that displays the calendar, you should modify it this way:
$day = $i - $startday + 1;
$thisDate = new DateTime("$cYear-$cMonth-$day");
$jsEvent[] = "document.getElementById('trigger" . $i . "').onclick = function() {showForm()};";
echo "<td align='center' valign='middle' height='20px'><a href='#' id='trigger" . $i . "'>". ($i - $startday + 1) . "</a>";
// $bookings is an associative array of the form array('0'=>array('date'=>'date_value', 'activityTitle'=>'activityTitle_value'))
foreach ($bookings as $key => $value) {
if ($thisDate->format('Y-m-d') === $value['date']->format('Y-m-d')) {
// this prints out the activity title
echo $value['activityTitle'];
}
}
I am using a calendar in which i am having trouble making the previous dates unavailable. At the moment my calendar ha links for each date and when you click a date it shows the value on another page. However i need all make all the dates that have already passed unavailable. I know it is something to do with the if statement near the end of the code but i can't figure it out. Here is my code
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
?>
<?php
$cMonth = isset($_REQUEST["month"]) ? $_REQUEST["month"] : date("n");
$cYear = isset($_REQUEST["year"]) ? $_REQUEST["year"] : date("Y");
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?><!DOCTYPE html>
<html>
<head>
<title>Hook Up</title>
</head>
<style type="text/css">
table {
border: 1px solid black;
border-collapse: collapse;
}
th {
border: 1px solid black;
padding: 6px;
font-weight: bold;
background: #ccc;
}
td {
border: 1px solid black;
padding: 6px;
vertical-align: top;
width: 100px;
}
</style>
<script type="text/javascript">
function eventWindow(url) {
event_popupWin = window.open(url, 'event',
'resizable=yes, scrollbars=yes, toolbar=no, width=400, height=400);
event_popupWin.opener = self;
}
</script>
<body>
<h1>Select a Night Out</h1>
<table width="200">
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" align="left"> Previous</td>
<td width="50%" align="right">Next </td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
$today = date('j');
$currentmonth = date('n');
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ){
echo "<tr>";
}
if($i < $startday){
echo ("<td class='cell cell_txt'> </td>");
} else {
if (($i - $startday + 1) == $today && $currentmonth == $cMonth){
echo ("<td class='cell_today cell_txt'>".($i-$startday+ 1)."</td>");
} else {
echo ("<td class='cell cell_txt'>".($i - $startday + 1)."</td>");
}
}
if(($i % 7) == 6 ) {
echo "</tr>\n";
}
}
?>
</table>
</td>
</tr>
</table>
</body>
</html>
If anyone can help it would be greatly appreciated. Cheers
if you add following line
$cDay = isset($_REQUEST["day"]) ? $_REQUEST["day"] : date("d");
below this line
$cYear = isset($_REQUEST["year"]) ? $_REQUEST["year"] : date("Y");
and change this line
if (($i - $startday + 1) == $today && $currentmonth == $cMonth){
to:
if ((($i - $startday + 1) == $today && $currentmonth == $cMonth) OR ( (($i - $startday + 1) == $cDay) && ($currentmonth == $cMonth)) ){
That will black out the date that is passed in.
If you want to pass in multiple dates, i.e. pick one date 2013-01-18, the page reloads and blanks out the 18th then want to pick a second date e.g. 2013-01-22 and have the page reload and blank out both the 18th and the 22nd then you will need to change the inputs to arrays and add the previous selected dates into hidden fields to be resubmitted.
If you just want to black out one date then the code changes will work.
Hope this helps.
Update to black out all previous date to the selected:
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
?>
<?php
$sMonth = isset($_REQUEST["smonth"]) ? $_REQUEST["smonth"] : date("n");
$sYear = isset($_REQUEST["syear"]) ? $_REQUEST["syear"] : date("Y");
$cMonth = isset($_REQUEST["month"]) ? $_REQUEST["month"] : '';
$cYear = isset($_REQUEST["year"]) ? $_REQUEST["year"] : '';
$cDay = isset($_REQUEST["day"]) ? $_REQUEST["day"] : '';
//echo __line__." Dates in ".$cDay." ".$cMonth.", ".$cYear."<br>";
$prev_year = $sYear;
$next_year = $sYear;
$prev_month = $sMonth - 1;
$next_month = $sMonth + 1;
if ($prev_month == 0) {
$prev_month = 12;
$prev_year = $sYear - 1;
}
if ($next_month == 13) {
$next_month = 1;
$next_year = $sYear + 1;
}
$nextPrevString = "&month=$cMonth&year=$cYear&day=$cDay";
$selectString = "&smonth=$sMonth&syear=$sYear";
?><!DOCTYPE html>
<html>
<head>
<title>Hook Up</title>
</head>
<style type="text/css">
table {
border: 1px solid black;
border-collapse: collapse;
}
th {
border: 1px solid black;
padding: 6px;
font-weight: bold;
background: #ccc;
}
td {
border: 1px solid black;
padding: 6px;
vertical-align: top;
width: 100px;
}
</style>
<script type="text/javascript">
function eventWindow(url) {
event_popupWin = window.open(url, 'event', resizable=yes, scrollbars=yes, toolbar=no, width=400, height=400);
event_popupWin.opener = self;
}
</script>
<body>
<h1>Select a Night Out</h1>
<table width="200">
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" align="left"> Previous</td>
<td width="50%" align="right">Next </td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$sMonth - 1] . ' ' . $sYear; ?></strong></td>
</tr>
<tr>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
</tr>
<?php
$timestamp = mktime(0, 0, 0, $sMonth, 1, $sYear);
if ($cDay != '') {
$selectedDate = mktime(0, 0, 0, $cMonth, $cDay, $cYear);
} else {
$selectedDate = 0;
}
$maxday = date("t", $timestamp);
$thismonth = getdate($timestamp);
$startday = $thismonth['wday'];
$today = date('j');
$currentmonth = date('n');
for ($i = 0; $i < ($maxday + $startday); $i++) {
if (($i % 7) == 0) {
echo "<tr>";
}
if ($i < $startday) {
echo ("<td class='cell cell_txt'> </td>");
} else {
$testDate = mktime(0, 0, 0, $sMonth, $i - $startday + 1, $sYear);
if ($testDate < $selectedDate) {
echo ("<td class='cell_today cell_txt'>" . ($i - $startday + 1) . "</td>");
} else {
echo ("<td class='cell cell_txt'>" . ($i - $startday + 1) . "</td>");
}
}
if (($i % 7) == 6) {
echo "</tr>\n";
}
}
?>
</table>
</td>
</tr>
</table>
</body>
</html>
<!-----use it will surely work -----!>
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
?>
<?php
if (!isset($_REQUEST["day"])) $_REQUEST["day"] = date("d");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
?>
<?php
$cDay = $_REQUEST["day"];
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth - 1;
$next_month = $cMonth + 1;
if ($prev_month == 0) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<div id="calendar_div" name="calendar_div">
<div class="table-responsive">
<table width="93%" style="border: none">
<tr>
<td> <a
href="<?php echo $_SERVER["PHP_SELF"] . "?month=" . $prev_month . "&year=" . $prev_year; ?>"
style="color:#FFFFFF"> < </a>
<a href="<?php echo $_SERVER["PHP_SELF"] . "?month=" . $next_month . "&year=" . $next_year; ?>"
style="color:#FFFFFF"> > </a></td>
<td style="float: right">
<h3 style="color: #ffffff;"> <?php echo $monthNames[$cMonth - 1] . ' ' . $cYear; ?></strong></h3>
</td>
</tr>
</table>
<table class="table">
<tr>
<td style="color:#FFFFFF;border: none"><strong>Sun</strong></td>
<td style="color:#FFFFFF;border: none"><strong>Mon</strong></td>
<td style="color:#FFFFFF;border: none"><strong>Tue</strong></td>
<td style="color:#FFFFFF;border: none"><strong>Wed</strong></td>
<td style="color:#FFFFFF;border: none"><strong>Thr</strong></td>
<td style="color:#FFFFFF;border: none"><strong>Fri</strong></td>
<td style="color:#FFFFFF;border: none"><strong>Sat</strong></td>
</tr>
<?php
$timestamp = mktime(0, 0, 0, $cMonth, 1, $cYear);
$maxday = date("t", $timestamp);
$thismonth = getdate($timestamp);
$currentmonth = date('n');
$startday = $thismonth['wday'];
for ($i = 0; $i < ($maxday + $startday); $i++) {
if (($i % 7) == 0) echo "<tr>\n";
if ($i < $startday) echo "<td style='border: none'></td>\n";
elseif(($i - $startday + 1) == $cDay && $currentmonth == $cMonth ){
echo "<td style='background-color: #cccccc'>". ($i - $startday + 1) ."</td>";}
else{
echo "<td style='color: #ffffff; border: none'>". ($i - $startday + 1) ."</td></a>";}
if(($i % 7) == 6 ) echo "</tr>";
}
?>
</table>