Jump to content

php event calendar


rockindano30

Recommended Posts

created this calendar in php. but now want to use it as an event calendar, where if the day has an event i want that day to be a link to cal.php page. i am trying to create it as a mysql database cal.

 

this is my code:

<?php
// Get values from query string
$day = $_GET["day"];
$month = $_GET["month"];
$year = $_GET["year"];
$sel = $_GET["sel"];
$what = $_GET["what"];


if($day == "")
$day = date("j");

if($month == "")
$month = date("m");

if($year == "")
$year = date("Y");

$currentTimeStamp = strtotime("$year-$month-$day");
$monthName = date("F", $currentTimeStamp);
$numDays = date("t", $currentTimeStamp);
$counter = 0;
$numEventsThisMonth = 0;
$hasEvent = false;
$todaysEvents = "";
?>
<table width="250" border='0' cellspacing='0' cellpadding='0'>
  <tr align="center">
    <td colspan='1' align="center"><input type='button' value='  ' onClick='goLastMonth(<?php echo $month . ", " . $year; ?>)'> 
    </td>
    <td colspan='5' align="center"><span class='title'><?php echo $monthName . " " . $year; ?></span>

    </td>
    <td width='20' colspan='1' align='right'><input type='button' value=' ' onClick='goNextMonth(<?php echo $month . ", " . $year; ?>)'>
     </td>
  </tr>
  <tr>
    <td class='style2'>S</td>
    <td width='18' class='style2'>M</td>
    <td width='35' class='style2'>T</td>
    <td width='37' class='style2'>W</td>
    <td width='35' class='style2'>T</td>
    <td width='67' class='style2'>F</td>
    <td class='style2'>S</td>
  </tr>
  <?php
$numDays = date("t", $currentTimeStamp);
for($i = 1; $i < $numDays+1; $i++, $counter++)
{
$timeStamp = strtotime("$year-$month-$i");
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 align='center'> </td>";

} //end if
//of course first thing first connect to db.
if(!($db = @ mysql_connect('localhost', 'user', 'password')))
            {
               echo 'Error: Could not connect to our database sorry for any inconvience.
Please try at a later time.';
               exit;
            }
            //select which database you want to edit
            mysql_select_db("databasename");
            $event_id = $_GET["event_id"];
            
            
            if(!isset($event_id))
                  {
                     $query = "SELECT * FROM calendar";
                     $result = mysql_query($query);
               
                     //goes through all records in database and retrieves the need ones.
                     while($r=mysql_fetch_array($result))
                     {   
                     //the format is $variable = $r["nameofmysqlcolumn"];
                     //modify these to match your mysql table columns
                     $event_id=$r["event_id"];
                     $date=$r["dateevent"];
                   

                     
if($counter % 7 == 0)
echo "</tr><tr align='center'>";
//echo "<td width='50' align='center'>$i</td>";
if(date("w", $timeStamp) == 0 || date("w", $timeStamp) == 6)
echo "<td width='50' class='weekend' align='center'>$i</td>";
else
if($i == date("d") && $month == date("m") && $year == date("Y"))
echo "<td width='50' class='today' align='center'>$i</td>";
else
if($date==$i)
echo "<td width='50' class='normal' align='center' style=\"background-color:black\"><a href=''>$i[/url]</td>";
else
echo "<td width='50' class='normal' align='center'>$i</td>";  }
                 }//end if///////////////////////////
}//end of for loop
?>
</table>

 

help!!!!!!!! please

 

 

rockindano30

Link to comment
https://forums.phpfreaks.com/topic/98010-php-event-calendar/
Share on other sites

What u need to do is query MySQL for all evenst in your "date range"

then in your while($row = mysql_fetch_assoc($r){

<?php
while($row = mysql_fetch_assoc($r)){
$event_data[date("y-m-d",strtotime($row['Date']))][] = $row;
}
?>

Then when u echo out a day in its <td> also do a foreach($event_data[THISDATE] as $key => $value){

and the $row is accessible right there for you. for all events on that date

Link to comment
https://forums.phpfreaks.com/topic/98010-php-event-calendar/#findComment-501481
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.