Jump to content

Creating a Even Calendar?


Nightmareinhell

Recommended Posts

Hello! First I would like to say welcome to the forums! I hope one day I'll be able to give back!!

 

Anyway, I seem to not know how to do this.  I'm creating a website for my guild, and I'm very very rusty with PHP (learned it a year or two back than lost it).  Anyway, I made the script to display the calendar portion of it (followed a tutorial), but I can't seem to import the feature to display events in the same cell as the date that its on.  Sorry my coding is a little sloppy :P but I'm hoping you guys can help xD  I left off with thinking that maybe i could use an array to do the job but I honestly have no clue how to go about this...

 

<?php
function calendar(){
include('connect.php');
$month = date("n");
$year = date("Y");
$query = "SELECT * FROM calendar WHERE (month='$month' AND year='$year')";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$firstDay1 = mktime(0,1,0,$month,1,$year);
$firstDay = mktime(0,1,0,$month,1,$year);
$daysInMonth = date("t",$firstDay);
$firstDay = date("w",$firstDay);
$day1 = array();
$message = array();
$message1 = '';
$dayNumber = 1;

$i = 0;
while ($i < $num) {
$day1[$i] = mysql_result($result,$i,"day");
$message[$i] = mysql_result($result,$i,"message");
$i++;
}

echo "<table width='280'  border='1'>\n";
  echo "<tr>\n";
    echo "<td align='center'>" . date("F Y") . "</td>\n";
  echo "</tr>\n";
  echo "<tr>\n";
    echo "<td>\n";
      echo "<table width='490'  border='0' cellspacing='2' cellpadding='2'>\n";
        echo "<tr align='center'>\n";
          echo "<td width='70'>Sun</td>\n";
          echo "<td width='70'>Mon</td>\n";
          echo "<td width='70'>Tue</td>\n";
          echo "<td width='70'>Wed</td>\n";
          echo "<td width='70'>Thu</td>\n";
          echo "<td width='70'>Fri</td>\n";
          echo "<td width='70'>Sat</td>\n";
        echo "</tr>\n";
        # Calculate number of rows
        $totalCells = $firstDay + $daysInMonth;
        if($totalCells < 36){
          $rowNumber = 5;
        } else {
          $rowNumber = 6;
        }
        # Create Rows
        for($currentRow=1; $currentRow <= $rowNumber; $currentRow++){
          if($currentRow == 1){
            # Create First Row
            echo "<tr align='center'>\n";
            for($currentCell  = 0; $currentCell<7; $currentCell++){
              if($currentCell == $firstDay){
                # First Day of the Month		
				if($day1 == $dayNumber){
					$message1 = $message;
				}
				else {
					$message1 = "";
				}
                 	 echo "<td width='70' height='50'>" . $dayNumber . "<br />$message1</td>\n";
                  	$dayNumber++;
		  } else {
                if($dayNumber > 1){
                  # First Day Passed so output Date	
			if($day1 == $dayNumber){  
			$message1 = $message;
			}
			else {
				//$message1 = "";
			}
                  echo "<td width='70' height='50'>" . $dayNumber . "<br />$message1</td>\n";
                  $dayNumber++;
			} else {
                  # First Day Not Reached so display blank cell
                  echo "<td width='70' height='50'> </td>\n";
                }
              }
            }
            echo "</tr>\n";
          } else {
            # Create Remaining Rows
            echo "<tr align='center'>\n";
            for($currentCell = 0; $currentCell < 7; $currentCell++){
              if($dayNumber > $daysInMonth){
                # Days in month exceeded so display blank cell
                  echo "<td width='70' height='50'> </td>\n";
              } else {	
			if($day1 == $dayNumber){
				$message1 = $message;
			}
		     else {
				$message1 = "";
			}
                  echo "<td width='70' height='50'>" . $dayNumber . "<br />$message1</td>\n";
                  $dayNumber++; 
		  }
            }
            echo "</tr>\n";
          }
        }
      echo "</table>\n";
    echo "</td>\n";
  echo "</tr>\n";
echo "</table>\n";
}
calendar();
?>

 

Thank you guys so much!!! It will mean alot to me and my guild xD!!

 

**EDIT**

Forgot to add, Database looks like this

 

id

day

month

year

message

 

Thanks again!

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.