PHP - Event Calendar
I got this Event Calendar Script off of a site and i like it but it reads from a Flat File Database and i would like it to read from a mysql database. Can someone help me set it up so it will read from a mysql database? here is the script where its calling from the flat file..
Code: [Select] $counterfilepath="calendar.txt"; if(file_exists($counterfilepath)) { $filehandle=fopen($counterfilepath,"r"); $pointer = 1; while(!feof($filehandle)) { $rowdata = fgets($filehandle); $day = floatval(substr($rowdata,3,2)); $eventlastpos = strpos($rowdata,'{')-1; if($eventlastpos<=0){$eventlastpos=255;} $event = rtrim(substr($rowdata,11,$eventlastpos-10)); $eventcaption = rtrim(substr($rowdata,$eventlastpos+2,strlen($rowdata))); $datalist = $this->eventsthismonth[$day]; $rowmonth = floatval(substr($rowdata,0,2)); $rowyear = floatval(substr($rowdata,6,4)); if($rowmonth==$month and $rowyear==$year) { if($eventcaption=="") {$eventcaption='';} else {$eventcaption='<b>'.$eventcaption.'</b><br>';} if($datalist=="") { $this->eventsthismonth[$day] = '<font name=Verdana size=1>'.$eventcaption.$event.'</font>'; } else { $this->eventsthismonth[$day] = $datalist.'<br><hr size=1 color=#E0E0E0><font name=Verdana size=1>'.$eventcaption.$event.'</font>'; } } $pointer = $pointer + 1; } fclose($filehandle); } and the flat file looks like this 07/13/2005|Technology Advisory Meeting{2:00pm Similar TutorialsThis topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=330163.0 howdy all I was wondering if anyone has any Basic Event calendar or a tutorial for a basic one.. I want to get a event calendar on my site but i want a basic one so i can tweak it to fit my likings. Thank you SilentHunter Hi, I am using the backbone.js and full calendar script in my website. However, on clicking OK in the popup to add events, no action is taking place. Actually the event should be displayed on that specific date on clicking OK. the cancel button is working fine. I am using the link http://blog.shinetech.com/2011/08/05.../#comment-2245 Help me please. Thank you in advance I am workin on a event calendar and i ran into a problem.. it shows the calendar and the today's date and 1 event on each month but i want it to show all the events for each month. my problem is i can't figure out how to loop it so it will.. here is where im having trouble at.. Code: [Select] for ($i=0; $i<($maxday+$startday); $i++) { if(($i % 7) == 0 ){ echo "<tr>"; } if($i < $startday){ echo ("<td bgcolor='414141'> </td>"); } else { if (($i - $startday + 1) == $today && $currentmonth == $cMonth && $currentyear == $cYear){ echo ("<td bgcolor='FF0000'><center><font color='FFFFFF'>".($i - $startday + 1)."</font></center></td>"); } else { [color=red]// this is where i need it to loop[/color] if (($i - $startday + 1) == $eday && $eMonth == $cMonth && $eYear == $cYear){ echo ("<td bgcolor='0000FF'><center><a class='info' href='#'><font color='FFFFFF'>".($i - $startday + 1)."<span>".$event."<hr><br>".$event_des."</span></font></a></center></td>"); } else { echo ("<td bgcolor='595959'><center><font color='FFFFFF'>".($i - $startday + 1)."</font></center></td>"); } } if(($i % 7) == 6 ) { echo "</tr>\n"; } } } i marked where the loop needs to go in red.. currently i have the sql query right above it in my script but i tried putting it where i need the loop and i get a error in there or it duplicates the calender and sometimes the numbers. can some please help me? Thank you Outsider_Child HI im sorry if i post in a wrong thread im new here and im still young on PHP environment.. here is my problem hope someone can help me to solve this one here we goes, i got a project that i need to make a event calendar. where the members can see the whole month calendar then if they click the day with mark the page bring them to other page where they can see what event going to have on that day. then if admin was log.in the admin can do add,edit,delete by simply clicking on the calendar... tnx if u have time please send me an email or leave message here or reply on this forum thank you so much Good day! I created a webpages and i have a login page consist of Username and Department. And i encountered problem in adding event in my calendar. This is the flow of my webpage: First I have a separate table for the user and calendar. In my user table it has a Username, Department, and Permission. In the permission I put True or False, only one user i put True because i want that user is the one who permitted to add event or if she is login the add event link appear, but if other login the add even0t did not appear. This is my code in login: <?php session_start(); session_regenerate_id(); if($_SESSION['loggedin']){ //the user is already logged in, lets redirect them to the other page header("Location:company.php"); } //require_once 'conn.php'; $db_name="dspi"; mysql_connect("localhost", "root", "") or die("Cannot connect to server"); mysql_select_db("$db_name")or die("Cannot select DB"); $department = mysql_real_escape_string($_POST['department']); $username = mysql_real_escape_string($_POST['username']); $sql=mysql_query("SELECT `Department`, `Username` FROM `tbllogin` WHERE `Department` = '{$department}' AND Username = '{$username}'") or die(mysql_error()); $ct = mysql_num_rows($sql); if($ct == 1) { // im guessing this means that the user is valid. $_SESSION['loggedin'] = true; // now that the user is valid we change the session value. $row = mysql_fetch_assoc($sql); $_SESSION['username'] = $row['Username'] ; $_SESSION['department'] = $row['Department']; $Departments=array('Accounting', 'Engineering', 'Finishing_Goods', 'HRAD', 'MIS', 'Packaging_and_Design', 'Production', 'Purchasing_Logistic', 'QA_and_Technical', 'Supply_Chain'); if (in_array($row['Department'], $Departments)){ header ('Location:company.php'); }else{ echo "Incorrect Username or Department"; header ('Location:index.php'); } } ?> and this is my code in calendar page: <?php session_start(); $host = "localhost"; $username = ""; $password = ""; $dbCnx = @mysql_connect($host, $username, $password) or die('Could not Connect to the database'); $dbName = 'dspi'; mysql_select_db($dbName); ?> <html> <body> <script> function goLastMonth(month, year){ // If the month is January, decrement the year if(month == 1){ --year; month = 13; } document.location.href = '<?=$_SERVER['PHP_SELF'];?>?month='+(month-1)+'&year='+year; } //next function function goNextMonth(month, year){ // If the month is December, increment the year if(month == 12){ ++year; month = 0; } document.location.href = '<?=$_SERVER['PHP_SELF'];?>?month='+(month+1)+'&year='+year; } function remChars(txtControl, txtCount, intMaxLength) { if(txtControl.value.length > intMaxLength) txtControl.value = txtControl.value.substring(0, (intMaxLength-1)); else txtCount.value = intMaxLength - txtControl.value.length; } function checkFilled() { var filled = 0 var x = document.form1.calName.value; //x = x.replace(/^\s+/,""); // strip leading spaces if (x.length > 0) {filled ++} var y = document.form1.calDesc.value; //y = y.replace(/^s+/,""); // strip leading spaces if (y.length > 0) {filled ++} if (filled == 2) { document.getElementById("Submit").disabled = false; } else {document.getElementById("Submit").disabled = true} // in case a field is filled then erased } </script> <?php //$todaysDate = date("n/j/Y"); //echo $todaysDate; // Get values from query string $day = (isset($_GET["day"])) ? $_GET['day'] : ""; $month = (isset($_GET["month"])) ? $_GET['month'] : ""; $year = (isset($_GET["year"])) ? $_GET['year'] : ""; //comparaters for today's date //$todaysDate = date("n/j/Y"); //$sel = (isset($_GET["sel"])) ? $_GET['sel'] : ""; //$what = (isset($_GET["what"])) ? $_GET['what'] : ""; //$day = (!isset($day)) ? $day = date("j") : $day = ""; if(empty($day)){ $day = date("j"); } if(empty($month)){ $month = date("n"); } if(empty($year)){ $year = date("Y"); } //set up vars for calendar etc $currentTimeStamp = strtotime("$year-$month-$day"); $monthName = date("F", $currentTimeStamp); $numDays = date("t", $currentTimeStamp); $counter = 0; //$numEventsThisMonth = 0; //$hasEvent = false; //$todaysEvents = ""; //run a selec statement to hi-light the days function hiLightEvt($eMonth,$eDay,$eYear){ //$tDayName = date("l"); $todaysDate = date("n/j/Y"); $dateToCompare = $eMonth . '/' . $eDay . '/' . $eYear; if($todaysDate == $dateToCompare){ //$aClass = '<span>' . $tDayName . '</span>'; $aClass='class="today"'; }else{ //$dateToCompare = $eMonth . '/' . $eDay . '/' . $eYear; //echo $todaysDate; //return; $sql="select count(calDate) as eCount from calTbl where calDate = '" . $eMonth . '/' . $eDay . '/' . $eYear . "'"; //echo $sql; //return; $result = mysql_query($sql); while($row= mysql_fetch_array($result)){ if($row['eCount'] >=1){ $aClass = 'class="event"'; }elseif($row['eCount'] ==0){ $aClass ='class="normal"'; } } } return $aClass; } ?> <div id="Calendar_Event"> <table width="350" cellpadding="0" cellspacing="0"> <tr> <td width="50" colspan="1"> <input type="button" value=" < " onClick="goLastMonth(<?php echo $month . ", " . $year; ?>);"> </td> <td width="250" colspan="5"> <span class="title" style="color:#FFFFFF"><?php echo $monthName . " " . $year; ?></span><br> </td> <td width="50" colspan="1" align="right"> <input type="button" value=" > " onClick="goNextMonth(<?php echo $month . ", " . $year; ?>);"> </td> </tr> <tr> <th>M</td> <th>T</td> <th>W</td> <th>T</td> <th>F</td> <th>S</td> <th>S</td> </tr> <tr> <?php for($i = 1; $i < $numDays+1; $i++, $counter++){ $dateToCompare = $month . '/' . $i . '/' . $year; $timeStamp = strtotime("$year-$month-$i"); //echo $timeStamp . '<br/>'; if($i == 1){ // Workout when the first day of the month is $firstDay = date("N", $timeStamp); for($j = 1; $j < $firstDay; $j++, $counter++){ echo "<td> </td>"; } } if($counter % 7 == 0 ){ ?> </tr><tr> <?php } ?> <!--right here--><td width="50" <?=hiLightEvt($month,$i,$year);?>><a href="<?=$_SERVER['PHP_SELF'] . '?month='. $month . '&day=' . $i . '&year=' . $year;?>&v=1"><?=$i;?></a></td> <?php } ?> </table> </div> <div id="New_Event"> <?php if(isset($_GET['v'])){ if(isset($_POST['Submit'])){ $sql="insert into calTbl(calName,calDesc,calDate,calStamp) values('" . $_POST['calName'] ."','" . $_POST['calDesc'] . "','" . $_POST['calDate'] . "',now())"; mysql_query($sql); } $sql="select calName,calDesc, DATE_FORMAT(calStamp, '%a %b %e %Y') as calStamp from calTbl where calDate = '" . $month . '/' . $day . '/' . $year . "'"; //echo $sql; //return; $result = mysql_query($sql); $numRows = mysql_num_rows($result); $check=mysql_query("SELECT * FROM tbllogin WHERE Username='xxx' AND Department='HRAD' AND Permission='True'"); mysql_fetch_array($check); if($check['Username']=='xxx' && $check['Department']=='HRAD'){ $_SESSION['isallowed'] = $check['Permission']; //if (mysql_num_rows($check)>0){ ?> <a href="<?=$_SERVER['PHP_SELF'];?>?month=<?=$_GET['month'] . '&day=' . $_GET['day'] . '&year=' . $_GET['year'];?>&v=1&f=true">Add Even</a><a href="<?=$_SERVER['PHP_SELF'];?>?month=<?=$_GET['month'] . '&day=' . $_GET['day'] . '&year=' . $_GET['year'];?>&v=1&f=true">t</a><?php }else{ echo 'You cannot Add New Event'; }?> </div> <div id="Cal_Event"> <?php if(isset($_GET['f'])){ include 'calform.php'; } if($numRows == 0 ){ echo ''; }else{ //echo '<ul>'; echo '<h3>Event Listed</h3>'; while($row = mysql_fetch_array($result)){ ?> <h5><?=$row['calName'];?></h5> <?=$row['calDesc'];?><br/> Listed On: <?=$row['calStamp'];?> <?php } } } ?> </div> </body> </html> In that code when the user log is xxx and when she click a date she want to add event the appear is "You cannot Add Event". I hope somebody can help me.. Thank you in advance... This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=348839.0 Hello guys I am developing my own system with event calendar but I stucked in the part where I should mark in the same way event which continue more than one day.What is my point - lets take for example google calendar, here you can see how the bar is purple for all 3 days marked for street cleaning : http://www.file-extensions.org/imgs/app-picture/6718/google-calendar.jpg Can you give me only an idea how I should proceed,what to use to achieve such result,what are my best options ? Thank you my problem is if my local date is february 1 or march 30... if i press previous month i cant see the month of february, but if i press the change the local date to february 2 or march 29 i can see the month of february in my event calendar... what should i do to see the month of february even i set the local date in february 1 or march 30.... heres the code Code: [Select] if (isset($_GET['day'])){ $day = $_GET['day']; } else { $day = date("j"); } if(isset($_GET['month'])){ $month = $_GET['month']; } else { $month = date("n"); } if(isset($_GET['year'])){ $year = $_GET['year']; }else{ $year = date("Y"); } $currentTimeStamp = strtotime( "$day-$month-$year"); $monthName = date("F", $currentTimeStamp); $numDays = date("t", $currentTimeStamp); Hi could anyone help me please. Hi: I am working with a PHP Event Calendar. I am having trouble displaying the data the way I want to. If a person clicks on a number/date in the calendar (17, for example) the data will display fine below the calendar.\ However, I want to display only the Event Title ("calName") in the date box as a link, and allow the user to click the title to go to a new page to see the full Event info. I can not get any of the data to display and hope someone can tell me what I'm doing wrong. This is the code: Code: [Select] <script> function goLastMonth(month, year){ // If the month is January, decrement the year if(month == 1){ --year; month = 13; } document.location.href = '<?=$_SERVER['PHP_SELF'];?>?month='+(month-1)+'&year='+year; } //next function function goNextMonth(month, year){ // If the month is December, increment the year if(month == 12){ ++year; month = 0; } document.location.href = '<?=$_SERVER['PHP_SELF'];?>?month='+(month+1)+'&year='+year; } function remChars(txtControl, txtCount, intMaxLength) { if(txtControl.value.length > intMaxLength) txtControl.value = txtControl.value.substring(0, (intMaxLength-1)); else txtCount.value = intMaxLength - txtControl.value.length; } function checkFilled() { var filled = 0 var x = document.form1.calName.value; //x = x.replace(/^\s+/,""); // strip leading spaces if (x.length > 0) {filled ++} var y = document.form1.calDesc.value; //y = y.replace(/^s+/,""); // strip leading spaces if (y.length > 0) {filled ++} if (filled == 2) { document.getElementById("Submit").disabled = false; } else {document.getElementById("Submit").disabled = true} // in case a field is filled then erased } </script> ............... <p> <div id="legend"> <img src="images/Cal-Icon.jpg" style="padding: 0 15px 15px 0;" /> Today is: <? $today = date("F j, Y, g:i a"); echo " $today " ?> </div> <?php //$todaysDate = date("n/j/Y"); //echo $todaysDate; // Get values from query string $day = (isset($_GET["day"])) ? $_GET['day'] : ""; $month = (isset($_GET["month"])) ? $_GET['month'] : ""; $year = (isset($_GET["year"])) ? $_GET['year'] : ""; //comparaters for today's date //$todaysDate = date("n/j/Y"); //$sel = (isset($_GET["sel"])) ? $_GET['sel'] : ""; //$what = (isset($_GET["what"])) ? $_GET['what'] : ""; //$day = (!isset($day)) ? $day = date("j") : $day = ""; //comparaters for today's date //$todaysDate = date("n/j/Y"); //$sel = (isset($_GET["sel"])) ? $_GET['sel'] : ""; //$what = (isset($_GET["what"])) ? $_GET['what'] : ""; //$day = (!isset($day)) ? $day = date("j") : $day = ""; if(empty($day)){ $day = date("j"); } if(empty($month)){ $month = date("n"); } if(empty($year)){ $year = date("Y"); } //set up vars for calendar etc $currentTimeStamp = strtotime("$year-$month-$day"); $monthName = date("F", $currentTimeStamp); $numDays = date("t", $currentTimeStamp); $counter = 0; //$numEventsThisMonth = 0; //$hasEvent = false; //$todaysEvents = ""; //run a selec statement to hi-light the days function hiLightEvt($eMonth,$eDay,$eYear){ //$tDayName = date("l"); $todaysDate = date("n/j/Y"); $dateToCompare = $eMonth . '/' . $eDay . '/' . $eYear; if($todaysDate == $dateToCompare){ //$aClass = '<span>' . $tDayName . '</span>'; $aClass='class="today"'; }else{ //$dateToCompare = $eMonth . '/' . $eDay . '/' . $eYear; //echo $todaysDate; //return; $sql="select count(calDate) as eCount from calTbl where calDate = '" . $eMonth . '/' . $eDay . '/' . $eYear . "'"; //echo $sql; //return; $result = mysql_query($sql); while($row= mysql_fetch_array($result)){ if($row['eCount'] >=1){ $aClass = 'class="event"'; }elseif($row['eCount'] ==0){ $aClass ='class="normal"'; } } } return $aClass; } ?> <table width="900" cellpadding="0" cellspacing="0"> <tr> <td width="50" colspan="1"> <input type="button" value=" < " onClick="goLastMonth(<?php echo $month . ", " . $year; ?>);"> </td> <td width="250" colspan="5"> <span class="title"><?php echo $monthName . " " . $year; ?></span><br> </td> <td width="50" colspan="1" align="right"> <input type="button" value=" > " onClick="goNextMonth(<?php echo $month . ", " . $year; ?>);"> </td> </tr> <tr> <th>S</th> <th>M</th> <th>T</th> <th>W</th> <th>T</th> <th>F</th> <th class="lastOne">S</th> </tr> <tr> <?php for($i = 1; $i < $numDays+1; $i++, $counter++){ $dateToCompare = $month . '/' . $i . '/' . $year; $timeStamp = strtotime("$year-$month-$i"); //echo $timeStamp . '<br/>'; if($i == 1){ // Workout when the first day of the month is $firstDay = date("w", $timeStamp); for($j = 0; $j < $firstDay; $j++, $counter++){ echo "<td> </td>"; } } if($counter % 7 == 0){ ?> </tr><tr> <?php } ?> <!--right here--><td width="128" <?=hiLightEvt($month,$i,$year);?>><a href="<?=$_SERVER['PHP_SELF'] . '?month='. $month . '&day=' . $i . '&year=' . $year;?>&v=1"><?=$i;?></a> // TRYING TO DISPLAY CALENDAR EVENTS HERE <?php $sql="select calName,calDesc, DATE_FORMAT(calStamp, '%a %b %e %Y') as calStamp from calTbl where calDate = '" . $month . '/' . $day . '/' . $year . "'"; //echo $sql; //return; $result = mysql_query($sql); $numRows = mysql_num_rows($result); ?> <? while($row = mysql_fetch_array($result)){ ?> <div class="output"> <h5><?=$row['calName'];?></h5> <?=$row['calDesc'];?><br/> Listed On: <?=$row['calStamp'];?> </div> </td> </table> // END OF TRYING TO DISPLAY CALENDAR EVENTS HERE <?php } } ?> </p> Can anyone tell me what is wrong? Thanks! I have events added to mysql on my site and wish to them also to be added to my Google Calendar. Is this possible? Hello ,
I am trying to display my planned events in calendar using full calendar json, jquery. But its not getting displayed, but its getting inserted. I am not very good at jquery or json. please somebody help me in this...
here is my code
in my calendar.php (display page)
<div class="span8"> <div class="w-box w-box-green"> <div class="w-box-header"></div> <div class="w-box-content"> <div id='calendar_json'></div> </div> <div class="w-box-footer"> <p class="f-text">JSON events fetched from a script</p> </div> </div> </div> </div>and in my calendar.js jsonEvents: function() { if($('#calendar_json').length) { $('#calendar_json').fullCalendar({ header: { left: 'month,agendaWeek,agendaDay', center: 'title', right: 'prev,next' }, buttonText: { prev: '<i class="icon-chevron-left icon-white cal_prev" />', next: '<i class="icon-chevron-right icon-white cal_next" />' }, editable: true, firstDay: 1, // 0 - Sunday, 1 - Monday events: "php_helpers/json-events.php", eventDrop: function(event, delta) { alert(event.title + ' was moved ' + delta + ' days\n' + '(should probably update your database)'); } }); }json-events.php include("connect.php"); $year = date('Y'); $month = date('m'); //$db=public_db_connect(); $year = date('Y'); $month = date('m'); $command = "SELECT * FROM planner"; $result = mysql_query($command) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { echo "hi"; //$start = date("D, j M Y G:i:s T", strtotime($row['start'])); //$end = date("D, j M Y G:i:s T", strtotime($row['end_time'])); $start = date("Y-m-d", strtotime($row['from_time'])); //$start = "$year-$month-20"; $myid = $row['plan_id']; $eventsArray['plan_id'] = (int)trim($myid); //$eventsArray['title'] = $row['title']; $title = $row['company']; //$title = $row['title']; //echo $title; $eventsArray['company'] = $title; $eventsArray['from_time'] = $start; $eventsArray['to_time'] = $start; $eventsArray['url'] = "edit_calendar.php?calendarid=".$row['plan_id']; // $eventsArray['end'] = $end; // $eventsArray['allDay'] = false; $events[] = $eventsArray; } echo json_encode($events); I have a listener which executes a HTTP request to a remote API before the User entity is persisted and uses the response to set one of the entity's properties. It will also listen for update and remove and will make the appropriate HTTP request to the API but will not modify the entity. All works as desired... Almost. If when persisting the entity, I have some error, the remote API and my application become out of sync. I wish to change my application to perform a second call to the API if an error occurs and reverse the previous call. My thoughts on how to implement a Place a try/catch block when executing the query. Don't like this approach. Add an ExceptionListener which somehow retrieves the entity and makes the applicable changes. Maybe part of the solution, but too complicated to be the full solution. When adding, updating, or deleting a user from the remote API under UserListener's three methods, adding a callback which gets executed upon a PDOException. I think this is the best approach and expanded my thoughts below.
<?php namespace App\EventListener; use Doctrine\Persistence\Event\LifecycleEventArgs; use App\Service\HelpDeskClient; use App\Entity\AbstractUser; final class UserListner { private $helpDeskClient; public function __construct(HelpDeskClient $helpDeskClient) { $this->helpDeskClient = $helpDeskClient; } public function prePersist(AbstractUser $user, LifecycleEventArgs $event) { $this->helpDeskClient->addUser($user); //$user will be updated with the HTTP response } public function preUpdate(AbstractUser $user, LifecycleEventArgs $event) { $this->helpDeskClient->updateUser($user); } public function preRemove (AbstractUser $user, LifecycleEventArgs $event) { $this->helpDeskClient->deleteUser($user); } } Okay, how do I actually do this? Was thinking of modifying UserListner as follows: //... use Symfony\Component\HttpKernel\KernelEvents; final class UserListner { // ... public function prePersist(AbstractUser $user, LifecycleEventArgs $event) { $this->helpDeskClient->addUser($user); $event->getObjectManager()->getEventManager()->addEventListener(KernelEvents::EXCEPTION, function($something) use($user) { // Use $this->helpDeskClient to reverse the changes }); } // Similar for update and remove }
But when trying this approach, I get a PDOException, but my callback never gets excecated. I've also tried replacing KernelEvents::EXCEPTION with '\PDOException' (note the quotes) with no success. Any ideas what I should be doing differently? Maybe some totally different approach? I suppose I could make the request to the API after the DB query is complete for updating and deleting, but not for adding. Hello there! I've been at this for too long! I've got a normal calendar at the side of my website that works fine, however i would like one that shows the next 7 days starting at today. I have an image here that kind of shows what i want... So it will show the next 7 days starting with today, and going into the next month if todays date is the 30th etc. Could anybody please help me? :\
Good Evening ! little help or a lot please ? I have coded a calendar on my site and am now trying to input the data info from MySQL into the calendar by PHP for each corresponding date...the calendar code works but I cant figure out how to get the info that's submitted in to the specified/corresponding date in the calendar :/ but I can get it to the bottom of the page. I've been at this 3 days and a million searches to find an example to follow but now I am at my wits end ! been about 15 years since I've done this. PLEASE help :) and thank you so much The HTML is good I can add to it if needed but the problem area is the calendar portion and putting it all in the right place without an error or code issue. I'm not sure how much more information i can provide. Like I said I am still trying to remember all of this stuff and trying to teach myself again and im not having much luck but i am a fast learner and can pickup by seeing how the code is written usually Here is my code: or at least the PHP portion of it. I hope this helps. <?php /*MAKES THE CONNECTION*/ include 'config.php'; $conn = mysqli_connect($servername, $username, $password, $dbname); // CHECK CONNECTION if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } /*DRAWS CALENDAR*// function draw_calendar($month,$year){ $calendar = '<table cellpadding="0" cellspacing="0" class="calendar">'; $headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); $calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>'; $running_day = date('w',mktime(0,0,0,$month,1,$year)); $days_in_month = date('t',mktime(0,0,0,$month,1,$year)); $days_in_this_week = 1; $day_counter = 0; $dates_array = array(); $start_day = $calendar.= '<tr class="calendar-row">'; for($x = 0; $x < $running_day; $x++): $calendar.= '<td class="calendar-day-np"> </td>'; $days_in_this_week++; endfor; for($list_day = 1; $list_day <= $days_in_month; $list_day++): $calendar.= '<td class="calendar-day">'; /* add in the day number */ $calendar.= '<div class="day-number">'.$list_day.'</div>'; /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !! IF MATCHES FOUND, PRINT THEM !! **/ $sql = "SELECT * FROM $tablename WHERE $current_epoch BETWEEN $start_day AND $end_day"; /** NEED TOQUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !! IF MATCHES FOUND, PRINT THEM !! **/ $calendar.= str_repeat('<p>'.$start_day.'</p>',2); $calendar.= '</td>'; if($running_day == 6): $calendar.= '</tr>'; if(($day_counter+1) != $days_in_month): $calendar.= '<tr class="calendar-row">'; endif; $running_day = -1; $days_in_this_week = 0; endif; $days_in_this_week++; $running_day++; $day_counter++; endfor; if($days_in_this_week < 8): for($x = 1; $x <= (8 - $days_in_this_week); $x++): $calendar.= '<td class="calendar-day-np"> </td>'; endfor; endif; /* final row */ $calendar.= '</tr>'; /* end the table */ $calendar.= '</table>'; return $calendar; } $sql = "SELECT id, name, phone, item, start_day, end_day, start_time, end_time FROM $tablename"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo $calendar. "id: " . $row["id"]. " - Name: " . $row["name"]. " - Phone: " . $row["phone"]. " - Item: " . $row["item"]. " - Start Day: " . $row["start_day"]. " - End Day: " . $row["end_day"]. " - Start Time: " . $row["start_time"]. " - End Time: " . $row["end_time"]. "<br>"; } } else { echo "0 results"; } /*END OF SHOWINGCALENDAR_________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________ */ $sql = "SELECT id, name, phone, item, start_day, end_day, start_time, end_time FROM $tablename"; $result = $conn->query($sql); /*GETS THE RESULTS OF THE CALENDAR FROM DATABASE TABLE*/ if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo $calendar. "id: " . $row["id"]. " - Name: " . $row["name"]. " - Phone: " . $row["phone"]. " - Item: " . $row["item"]. " - Start Day: " . $row["start_day"]. " - End Day: " . $row["end_day"]. " - Start Time: " . $row["start_time"]. " - End Time: " . $row["end_time"]. "<br>"; } } else { echo "0 results"; } Edited January 18 by Isfun42ofus Hello Guys, My goal is to make a Php and SQL calendar. I started learning php and sql a while ago, and basically got distracted. I'm now back, with a new project in the unhelpful position of having forgotten most of what I had learnt! I am making a project where I want to make a booking system. I have 3 rooms that are available to be booked Room 1, Room 2 and Room 3. I want to make a table that displays the current year in the top row, with the option to be able to click on a '<' or a '>' to change years. I want the same option for months and weeks. I think I am happy with how I would do this. The next bit is more tricky. I want a column for each of the days of the week. directly under this I want to display the correct date, under the correct day, starting with the current week we are on. for example it might look like this: ------------------------------------------- | < 2012 > | ------------------------------------------- | < March > | ------------------------------------------- | < 2 > | ------------------------------------------- |mon | tues | wed| thur | fri | sat | sun | | 5th | 6th | 7th| 8th |9th |10th| 11th | --------------------------------------------- Room 1 | yes | | | | | | | ---------------------------------------------- Room 2 | | | yes | | | | | ---------------------------------------------- Room 3 | | | | |yes | | | ---------------------------------------------- Although at the moment I'm struggling with the whole flippin' thing, the main issue is getting the correct dates to line up under the correct days of the week. I'm not asking for you to do this for me- but a bit of gentle help in this, and maybe some general advice in what I'm trying to achieve would be really useful! Regards, AJLX hi, i have implemented a calendar in php and added contols to display the previous and next months. How will I enhance my code to add links to display the previous and next year calendars? My code is as follows: Code: [Select] <?php session_start(); $_SESSION['username']; $_SESSION['unique_id']; $username = $_SESSION['username']; $unique_id = $_SESSION['unique_id']; ?> <?php $host = "localhost"; $user=""; $password=""; $db_name=""; $tbl_name=""; $con = mysql_connect("localhost","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$db_name", $con); // Now we need to define "A DAY", which will be used later in the script: define("ADAY", (60*60*24)); // The rest of the script will stay the same until about line 82 if ((!isset($_GET['month'])) || (!isset($_GET['year']))) { $nowArray = getdate(); $month = $nowArray['mon']; //mon - Numeric representation of a month $year = $nowArray['year']; } else { $month = $_GET['month']; $year = $_GET['year']; } $start = mktime(12,0,0,$month,1,$year); $firstDayArray = getdate($start); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title><?php echo "Calendar: ".$firstDayArray['month']."" . $firstDayArray['year']; ?></title> <link type="text/css" href="css/style_inner.css" rel="stylesheet" /> </head> <body> <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>" style="padding-top:50px"> <?php /* "next month" control */ $next_month = '<a href="?month='.($month != 12 ? $month + 1 : 1).'&year='.($month != 12 ? $year : $year + 1).'" class="control" style="text-decoration:none; padding-left:50px;">Next Month ></a>'; /* "previous month" control */ $previous_month = '<a href="?month='.($month != 1 ? $month - 1 : 12).'&year='.($month != 1 ? $year : $year - 1).'" class="control" style="text-decoration:none; padding-left:200px; padding-right:50px;">< Previous Month</a>'; /*$next_year = '<a href="?year='.($year != 2050 ? $year + 1 : 1).'&year='.($year != 2050 ? $year : $year + 1).'" class="control" style="text-decoration:none; padding-left:10px;">Next Year >></a>'; $previous_year = '<a href="?month='.($year != 2011 ? $year - 1 : 2050).'&year='.($year != 2011 ? $year : $year - 1).'" class="control" style="text-decoration:none; padding-left:150px;"><< Previous Year</a>'; echo $previous_year;*/ echo $previous_month; ?> <select name="month"><br/> <?php $months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); for ($x=1; $x<=count($months); $x++){ echo "<option value=\"$x\""; if ($x == $month){ echo " selected"; } echo ">".$months[$x-1]."</option>"; } ?> </select> <select name="year"> <?php for ($x=2011; $x<=2050; $x++){ echo "<option"; if ($x == $year){ echo " selected"; } echo ">$x</option>"; } ?> </select> <input type="submit" name="submit" value="Go!"> <?php echo $next_month; /*echo $next_year;*/ ?> </form> <br /> <?php $days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); echo "<table border=\"1\" style=\"padding-left:100px;\"><tr>\n"; foreach ($days as $day) { echo "<td style=\"background-color: #000000; width: 100px\" align=\"center\"> <strong style=\"color:#FFFFFF;\">$day</strong></td>\n"; } for ($count=0; $count < (6*7); $count++) { $dayArray = getdate($start); if (($count % 7) == 0) { if ($dayArray["mon"] != $month) { break; } else { echo "</tr><tr>\n"; } } if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) { //wday - Numeric representation of the day of the week echo "<td height=\"110px\"> </td>\n"; } else { //mday - Numeric representation of the day of the month $chkEvent_sql = "SELECT event_title, event_shortdesc FROM calendar_events WHERE month(event_start) = '".$month."' AND dayofmonth(event_start) = '".$dayArray["mday"]."' AND year(event_start) = '".$year."' ORDER BY event_start"; $chkEvent_res = mysql_query($chkEvent_sql, $con) or die(mysql_error($con)); if (mysql_num_rows($chkEvent_res) > 0) { $event_title = "<br/>"; while ($ev = mysql_fetch_array($chkEvent_res)) { $event_title .= "<font color=\"#006600\">" . stripslashes($ev["event_title"])."</font><br/>"; //$event_shortdesc .= stripslashes($ev["event_shortdesc"])."<br/>"; } mysql_free_result($chkEvent_res); } else { $event_title = ""; $event_shortdesc = ""; } echo "<td height=\"110px\" style=\"color : #0000CC;\">".$dayArray["mday"]."<a href=\"event.php?m=".$month."&d=".$dayArray["mday"]."&y=".$year."\" style=\"text-decoration:none;\"><img src=\"images/Add Event.jpg\" alt=\"Add Event\" title=\"Add Event\" height=\"20px\" width=\"20px\" style=\"padding-left:20px;\"/></a><br/>".$event_title."</td>\n"; unset($event_title); $start += ADAY; } } echo "</tr></table>"; mysql_close($con); ?> </body> </html> Please help me out its urgent.. Thank you in advance... |