
Event Calendar
The event calendar is an exceptionally valuable component for a web extend. Utilizing it you can add the occasion to the date-book alongside the separate date. Today we’ll examine how might you make a PHP Event Calendar effectively utilizing jQuery and Ajax.
Live Demo Download Source CodeIn the accompanying script, we’ll assemble a PHP timetable and bring the occasions from the MySQL database and show those occasions alongside the date-book date. We’ll utilize jQuery, Ajax and PHP for building the occasion schedule. Presently we are going to making an occasion schedule utilizing jQuery, Ajax, PHP and MySQL.
index.php
<!DOCTYPE html> <html> <title>Demo|Lisenme</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="css.css"> <link type="text/css" rel="stylesheet" href="style.css"/> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Oswald"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open Sans"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <script src="jquery.min.js"></script> <style> h1,h2,h3,h4,h5,h6 {font-family: "Oswald"} body {font-family: "Open Sans"} </style> <script> $(function() { $( "#skills" ).autocomplete({ source: 'search.php' }); }); </script> <?php include_once('functions.php'); ?> <body class="w3-light-grey"> <!-- Navigation bar with social media icons --> <div class="w3-bar w3-black w3-hide-small"> <a href="https://www.facebook.com/lisenme/" class="w3-bar-item w3-button"><i class="fa fa-facebook-official"></i></a> <a href="https://twitter.com/LisenMee" class="w3-bar-item w3-button"><i class="fa fa-twitter"></i></a> <a href="https://www.youtube.com/channel/UCEdC6Qk_DZ9fX_gUYFJ1tsA" class="w3-bar-item w3-button"><i class="fa fa-youtube"></i></a> <a href="https://plus.google.com/115714479889692934329" class="w3-bar-item w3-button"><i class="fa fa-google"></i></a> <a href="https://www.linkedin.com/in/lisen-me-b017a8137/" class="w3-bar-item w3-button"><i class="fa fa-linkedin"></i></a> </div> <!-- w3-content defines a container for fixed size centered content, and is wrapped around the whole page content, except for the footer in this example --> <div class="w3-content" style="max-width:1600px"> <!-- Header --> <header class="w3-container w3-center w3-padding-48 w3-white"> <h1 class="w3-xxxlarge"><a href="http://www.lisenme.com/"><img src="img/logo.jpg" alt="Girl Hat" style="width:20%" class="w3-padding-16"></a></h1> <h6>Welcome to our <span class="w3-tag">Tutorial</span></h6> </header> <!-- Image header --> <!-- Grid --> <div class="w3-row w3-padding w3-border"> <!-- Blog entries --> <div class="w3-col l12 s12"> <!-- Blog entry --> <div class="w3-container w3-white w3-margin w3-padding-large"> <h2 style="text-align: center";>PHP Event Calendar by Lisenme</h2> <br> <div id="calendar_div"> <?php echo getCalender(); ?> </div> </div> </div> </div> </div> </body> </html>
functions.php
<?php /* * Function requested by Ajax */ if(isset($_POST['func']) && !empty($_POST['func'])){ switch($_POST['func']){ case 'getCalender': getCalender($_POST['year'],$_POST['month']); break; case 'getEvents': getEvents($_POST['date']); break; default: break; } } /* * Get calendar full HTML */ function getCalender($year = '',$month = '') { $dateYear = ($year != '')?$year:date("Y"); $dateMonth = ($month != '')?$month:date("m"); $date = $dateYear.'-'.$dateMonth.'-01'; $currentMonthFirstDay = date("N",strtotime($date)); $totalDaysOfMonth = cal_days_in_month(CAL_GREGORIAN,$dateMonth,$dateYear); $totalDaysOfMonthDisplay = ($currentMonthFirstDay == 7)?($totalDaysOfMonth):($totalDaysOfMonth + $currentMonthFirstDay); $boxDisplay = ($totalDaysOfMonthDisplay <= 35)?35:42; ?> <div id="calender_section"> <h2> <a href="javascript:void(0);" onclick="getCalendar('calendar_div','<?php echo date("Y",strtotime($date.' - 1 Month')); ?>','<?php echo date("m",strtotime($date.' - 1 Month')); ?>');"><<</a> <select name="month_dropdown" class="month_dropdown dropdown"><?php echo getAllMonths($dateMonth); ?></select> <select name="year_dropdown" class="year_dropdown dropdown"><?php echo getYearList($dateYear); ?></select> <a href="javascript:void(0);" onclick="getCalendar('calendar_div','<?php echo date("Y",strtotime($date.' + 1 Month')); ?>','<?php echo date("m",strtotime($date.' + 1 Month')); ?>');">>></a> </h2> <div id="event_list" class="none"></div> <div id="calender_section_top"> <ul> <li>Sun</li> <li>Mon</li> <li>Tue</li> <li>Wed</li> <li>Thu</li> <li>Fri</li> <li>Sat</li> </ul> </div> <div id="calender_section_bot"> <ul> <?php $dayCount = 1; for($cb=1;$cb<=$boxDisplay;$cb++){ if(($cb >= $currentMonthFirstDay+1 || $currentMonthFirstDay == 7) && $cb <= ($totalDaysOfMonthDisplay)){ //Current date $currentDate = $dateYear.'-'.$dateMonth.'-'.$dayCount; $eventNum = 0; //Include db configuration file include 'dbConfig.php'; //Get number of events based on the current date $result = $db->query("SELECT title FROM events WHERE date = '".$currentDate."' AND status = 1"); $eventNum = $result->num_rows; //Define date cell color if(strtotime($currentDate) == strtotime(date("Y-m-d"))){ echo '<li date="'.$currentDate.'" class="grey date_cell">'; }elseif($eventNum > 0){ echo '<li date="'.$currentDate.'" class="light_sky date_cell">'; }else{ echo '<li date="'.$currentDate.'" class="date_cell">'; } //Date cell echo '<span>'; echo $dayCount; echo '</span>'; //Hover event popup echo '<div id="date_popup_'.$currentDate.'" class="date_popup_wrap none">'; echo '<div class="date_window">'; echo '<div class="popup_event">Events ('.$eventNum.')</div>'; echo ($eventNum > 0)?'<a href="javascript:;" onclick="getEvents(\''.$currentDate.'\');">view events</a>':''; echo '</div></div>'; echo '</li>'; $dayCount++; ?> <?php }else{ ?> <li><span> </span></li> <?php } } ?> </ul> </div> </div> <script type="text/javascript"> function getCalendar(target_div,year,month){ $.ajax({ type:'POST', url:'functions.php', data:'func=getCalender&year='+year+'&month='+month, success:function(html){ $('#'+target_div).html(html); } }); } function getEvents(date){ $.ajax({ type:'POST', url:'functions.php', data:'func=getEvents&date='+date, success:function(html){ $('#event_list').html(html); $('#event_list').slideDown('slow'); } }); } function addEvent(date){ $.ajax({ type:'POST', url:'functions.php', data:'func=addEvent&date='+date, success:function(html){ $('#event_list').html(html); $('#event_list').slideDown('slow'); } }); } $(document).ready(function(){ $('.date_cell').mouseenter(function(){ date = $(this).attr('date'); $(".date_popup_wrap").fadeOut(); $("#date_popup_"+date).fadeIn(); }); $('.date_cell').mouseleave(function(){ $(".date_popup_wrap").fadeOut(); }); $('.month_dropdown').on('change',function(){ getCalendar('calendar_div',$('.year_dropdown').val(),$('.month_dropdown').val()); }); $('.year_dropdown').on('change',function(){ getCalendar('calendar_div',$('.year_dropdown').val(),$('.month_dropdown').val()); }); $(document).click(function(){ $('#event_list').slideUp('slow'); }); }); </script> <?php } /* * Get months options list. */ function getAllMonths($selected = ''){ $options = ''; for($i=1;$i<=12;$i++) { $value = ($i < 10)?'0'.$i:$i; $selectedOpt = ($value == $selected)?'selected':''; $options .= '<option value="'.$value.'" '.$selectedOpt.' >'.date("F", mktime(0, 0, 0, $i+1, 0, 0)).'</option>'; } return $options; } /* * Get years options list. */ function getYearList($selected = ''){ $options = ''; for($i=2015;$i<=2025;$i++) { $selectedOpt = ($i == $selected)?'selected':''; $options .= '<option value="'.$i.'" '.$selectedOpt.' >'.$i.'</option>'; } return $options; } /* * Get events by date */ function getEvents($date = ''){ //Include db configuration file include 'dbConfig.php'; $eventListHTML = ''; $date = $date?$date:date("Y-m-d"); //Get events based on the current date $result = $db->query("SELECT title FROM events WHERE date = '".$date."' AND status = 1"); if($result->num_rows > 0){ $eventListHTML = '<h2>Events on '.date("l, d M Y",strtotime($date)).'</h2>'; $eventListHTML .= '<ul>'; while($row = $result->fetch_assoc()){ $eventListHTML .= '<li>'.$row['title'].'</li>'; } $eventListHTML .= '</ul>'; } echo $eventListHTML; } ?>
style.css
body{ font-family: sans-serif;} .none{ display:none;} .dropdown{color: #444444;font-size:17px;} #calender_section{ width:700px; margin:30px auto 0;} #calender_section h2{ background-color:#efefef; color:#444444; font-size:17px; text-align:center; line-height:40px;} #calender_section h2 a{ color:#F58220; float:none;} #calender_section_top{ width:100%; float:left; margin-top:20px;} #calender_section_top ul{padding:0; list-style-type:none;} #calender_section_top ul li{ float:left; display:block; width:99px; border-right:1px solid #fff; text-align:center; font-size:14px; min-height:0; background:none; box-shadow:none; margin:0; padding:0;} #calender_section_bot{ width:100%; margin-top:20px; float:left; border-left:1px solid #ccc; border-bottom:1px solid #ccc;} #calender_section_bot ul{ margin:0; padding:0; list-style-type:none;} #calender_section_bot ul li{ float:left; width:99px; height:80px; text-align:center; border-top:1px solid #ccc; border-right:1px solid #ccc; min-height:0; background:none; box-shadow:none; margin:0; padding:0; position:relative;} #calender_section_bot ul li span{ margin-top:7px; float:left; margin-left:7px; text-align:center;} .grey{ background-color:#DDDDDD !important;} .light_sky{ background-color:#B9FFFF !important;} /*========== Hover Popup ===============*/ .date_cell { cursor: pointer; cursor: hand; } .date_cell:hover { background: #DDDDDD !important; } .date_popup_wrap { position: absolute; width: 143px; height: 115px; z-index: 9999; top: -115px; left:-55px; background: transparent url(add-new-event.png) no-repeat top left; color: #666 !important; } .events_window { overflow: hidden; overflow-y: auto; width: 133px; height: 115px; margin-top: 28px; margin-left: 25px; } .event_wrap { margin-bottom: 10px; padding-bottom: 10px; border-bottom: solid 1px #E4E4E7; font-size: 12px; padding: 3px; } .date_window { margin-top:20px; margin-bottom: 2px; padding: 5px; font-size: 16px; margin-left:9px; margin-right:14px } .popup_event { margin-bottom: 2px; padding: 2px; font-size: 16px; width:100%; } .popup_event a {color: #000000 !important;} .packeg_box a {color: #F58220;float: right;} a:hover {color: #181919;text-decoration: underline;} @media only screen and (min-width:480px) and (max-width:767px) { #calender_section{ width:336px;} #calender_section_top ul li{ width:47px;} #calender_section_bot ul li{ width:47px;} } @media only screen and (min-width: 320px) and (max-width: 479px) { #calender_section{ width:219px;} #calender_section_top ul li{ width:30px; font-size:11px;} #calender_section_bot ul li{ width:30px;} #calender_section_bot{ width:217px;} #calender_section_bot ul li{ height:50px;} } @media only screen and (min-width: 768px) and (max-width: 1023px) { #calender_section{ width:530px;} #calender_section_top ul li{ width:74px;} #calender_section_bot ul li{ width:74px;} #calender_section_bot{ width:525px;} #calender_section_bot ul li{ height:50px;} }
dbconfig.php
<?php //db details $dbHost = 'localhost'; $dbUsername = 'root'; $dbPassword = ''; $dbName = 'lisenme'; //Connect and select the database $db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName); if ($db->connect_error) { die("Connection failed: " . $db->connect_error); } ?>
hi there why did’nt the popups show up when i hover on the calendar i think there are missing codes 🙁
which file is search.php in javascript
sorry jquery in index file…event is not showing in my calendar
there is no add event
There is no calendar. It’s just dates and days but not in calendar format as shown
It’s not hovering at all…