Calendar Fuctionality

I have created a simple basic calendar as the script shows below but can anyone tell me or show me how i can turn this into an event calendar so that when you click on a hyperlinked date it take you to a page which displays the event from a mysql database.

code:

[php]<?php
function showCalendar(){
// Get key day informations.
// We need the first and last day of the month and the actual day
$today = getdate();
$firstDay = getdate(mktime(0,0,0,$today[‘mon’],1,$today[‘year’]));
$lastDay = getdate(mktime(0,0,0,$today[‘mon’]+1,0,$today[‘year’]));

// Create a table with the necessary header informations
echo '<table>';
echo '  <tr><th colspan="7">'.$today['month']." - ".$today['year']."</th></tr>";
echo '<tr class="days">';
echo '  <td>Mo</td><td>Tu</td><td>We</td><td>Th</td>';
echo '  <td>Fr</td><td>Sa</td><td>Su</td></tr>';


// Display the first calendar row with correct positioning
echo '<tr>';
for($i=1;$i<$firstDay['wday'];$i++){
    echo '<td>&nbsp;</td>';
}
$actday = 0;
for($i=$firstDay['wday'];$i<=7;$i++){
    $actday++;
    if ($actday == $today['mday']) {
        $class = ' class="actday"';
    } else {
        $class = '';
    }
    echo "<td$class>$actday</td>";
}
echo '</tr>';

//Get how many complete weeks are in the actual month
$fullWeeks = floor(($lastDay['mday']-$actday)/7);

for ($i=0;$i<$fullWeeks;$i++){
    echo '<tr>';
    for ($j=0;$j<7;$j++){
        $actday++;
        if ($actday == $today['mday']) {
            $class = ' class="actday"';
        } else {
            $class = '';
        }
        echo "<td$class>$actday</td>";
    }
    echo '</tr>';
}

//Now display the rest of the month
if ($actday <$lastDay['mday']){
    echo '<tr>';
    
    for ($i=0; $i<7;$i++){
        $actday++;
        if ($actday == $today['mday']) {
            $class = ' class="actday"';
        } else {
            $class = '';
        }
        
        if ($actday <= $lastDay['mday']){
            echo "<td$class>$actday</td>";
        }
        else {
            echo '<td>&nbsp;</td>';
        }
    }
    
    
    echo '</tr>';
}

echo '</table>';

}

showCalendar();
?>
[/php]

Any help would be much appreciated

One way of doing it would be run a query each time a new day is created.

$q = “SELECT events, id, date FROM events_tbl WHERE date = ‘$date’”;

Then check to see if their were any returned rows mysql_num_rows()

If so you then would have a link displayed…

View Events

Then in the event_view.php page I would use the $_GET[’’] function to pull the date out of the URL. And use that date to then query the database for the appropriate information.

There are many ways to do something like this and what I describe above is only one way. I guess you just have to start working on it and if you get stuck on something specific, we are here to help!

Sponsor our Newsletter | Privacy Policy | Terms of Service