Jump to content

Event Calendar not fully functioning


versaskyla2111

Recommended Posts

Hi could anyone help me please.

 

I have this code and tried to do event calendar and retrieve the event data from mysql phpMyAdmin. 

My problem is current year doesnt display all data from database on the calendar.

 

example i've manually add data from January until May for current year (2014) but it only display the data for May only. it seems that other data is not been display properly.

 

another problem is that im stuck with, example when im in current month (example May) all data is display but when i've click the navigation link to go to the previous month and when i go back to current month (May) the event that has been mark on the calendar is missing. 

 

PLEASE i need this to be done this week or else im dead!

 

 

//config.php 

 


<?php

 

/* Define MySQL connection details and database table name */ 

$SETTINGS["hostname"]='localhost';

$SETTINGS["mysql_user"]='root';

$SETTINGS["mysql_pass"]='';

$SETTINGS["mysql_database"]='talentlo';

$SETTINGS["data_table"]='event_calendar';

 

/* Connect to MySQL */

 

if (!isset($install) or $install != '1') {

$connection = mysql_connect($SETTINGS["hostname"], $SETTINGS["mysql_user"], $SETTINGS["mysql_pass"]) or die ('Unable to connect to MySQL server.<br ><br >Please make sure your MySQL login details are correct.');

$db = mysql_select_db($SETTINGS["mysql_database"], $connection) or die ('request "Unable to select database."');

};

?>

 

 

 


 

 

//calendar.php

 

<?php


 

 

error_reporting(0);

include("config.php");

 

/// get current month and year and store them in $cMonth and $cYear variables

(intval($_REQUEST["month"])>0) ? $cMonth = intval($_REQUEST["month"]) : $cMonth = date("m");

(intval($_REQUEST["year"])>0) ? $cYear = intval($_REQUEST["year"]) : $cYear = date("Y");

 

// generate an array with all dates with events

$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE `event_date` LIKE '".$cYear."-".$cMonth."-%'";

$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);

while ($row = mysql_fetch_assoc($sql_result)) {

$events[$row["event_date"]]["title"] = $row["title"];

$events[$row["event_date"]]["description"] = $row["description"];

$events[$row["event_date"]]["venue"] = $row["venue"];

$events[$row["event_date"]]["time"] = $row["time"];

$events[$row["event_date"]]["date"] = $row["event_date"];

}

 

// calculate next and prev month and year used for next / prev month navigation links and store them in respective variables

$prev_year = $cYear;

$next_year = $cYear;

$prev_month = intval($cMonth)-1;

$next_month = intval($cMonth)+1;

 

// if current month is December or January month navigation links have to be updated to point to next / prev years

if ($cMonth == 12 ) {

$next_month = 1;

$next_year = $cYear + 1;

} elseif ($cMonth == 1 ) {

$prev_month = 12;

$prev_year = $cYear - 1;

}

 

if ($prev_month<10) $prev_month = '0'.$prev_month;

if ($next_month<10) $next_month = '0'.$next_month;

?>

  <table width="100%">

  <tr>

      <td class="mNav"><a href="javascript:LoadMonth('<?php echo $prev_month; ?>', '<?php echo $prev_year; ?>')"><<</a></td>

      <td colspan="5" class="cMonth"><?php echo date("F, Y",strtotime($cYear."-".$cMonth."-01")); ?></td>

      <td class="mNav"><a href="javascript:LoadMonth('<?php echo $next_month; ?>', '<?php echo $next_year; ?>')">>></a></td>

  </tr>

  <tr>

      <td class="wDays">Monday</td>

      <td class="wDays">Tuesday</td>

      <td class="wDays">Wednesday</td>

      <td class="wDays">Thursday</td>

      <td class="wDays">Friday</td>

      <td class="wDays">Saturday</td>

      <td class="wDays">Sunday</td>

  </tr>

<?php 

$first_day_timestamp = mktime(0,0,0,$cMonth,1,$cYear); // time stamp for first day of the month used to calculate 

$maxday = date("t",$first_day_timestamp); // number of days in current month

$thismonth = getdate($first_day_timestamp); // find out which day of the week the first date of the month is

$startday = $thismonth['wday'] - 1; // 0 is for Sunday and as we want week to start on Mon we subtract 1

 

for ($i=0; $i<($maxday+$startday); $i++) {

 

if (($i % 7) == 0 ) echo "<tr>";

 

if ($i < $startday) { echo "<td> </td>"; continue; };

 

$current_day = $i - $startday + 1;

if ($current_day<10) $current_day = '0'.$current_day;

 

// set css class name based on number of events for that day

if ($events[$cYear."-".$cMonth."-".$current_day]<>'') {

$css='withevent';

$click = "onclick=\"LoadEvents('".$cYear."-".$cMonth."-".$current_day."')\"";

} else {

$css='noevent';

$click = '';

}

 

echo "<td class='".$css."'".$click.">". $current_day . "</td>";

 

if (($i % 7) == 6 ) echo "</tr>";

}

?> 

</table>

 

 

//events.php

 

<?php

 

 

error_reporting(0);

include("config.php");

 

$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE `event_date` = '".mysql_real_escape_string($_REQUEST["date"])."'";

$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);

while ($row = mysql_fetch_assoc($sql_result)) {

echo "<h2>".stripcslashes($row["title"])."</h2>";

// echo "<span>".stripcslashes($row["description"])."</span>";

echo "<span>".stripcslashes($row["venue"])."</span>";

echo "<br />";

echo "<span>".stripcslashes($row["time"])."</span>";

 

 

 

}

?>

 

 

//index.html

 


 


<!DOCTYPE html>

<html lang="en">

<!-- MEGAFOLIO LIGHTBOX FILES  -->

<link href="css/calendar.css" rel="stylesheet" type="text/css" />

 

<head>

 

</head>

<body>


<div id="Calendar" > </div>

                <div id="Events" > </div>

                <script language="javascript" src="js/calendar.js"></script>

</body>

</html>

 

 

//calendar.js

 

var bustcachevar=1; //bust potential caching of external pages after initial request? (1=yes, 0=no)

var bustcacheparameter="";

 

function createRequestObject(){

try {

xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");

} catch(e) {

alert('Sorry, but your browser doesn\'t support XMLHttpRequest.');

};

return xmlhttp;

};

 

function ajaxpage(url, containerid){

var page_request = createRequestObject();

 

if (bustcachevar) bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()

page_request.open('GET', url+bustcacheparameter, true)

page_request.send(null)

 

page_request.onreadystatechange=function(){

loadpage(page_request, containerid)

}

 

}

 

function loadpage(page_request, containerid){

if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {

   document.getElementById(containerid).innerHTML=page_request.responseText;

};

}

 

 

function LoadMonth(month, year) {

ajaxpage("calendar.php?month="+month+"&year="+year, "Calendar")

}

 

function LoadEvents(date) {

ajaxpage("events.php?date="+date, "Events")

}

 

LoadMonth();calendar.css

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.