/    Sign up×
Community /Pin to ProfileBookmark

PHP outputting a calendar and sorting items into it

This is my code so far..

[code=php]
<section id=”content” class=”planner”>
<h2>
<?php
$date_db = strtotime(“07/01/2011”);
echo date(“F Y”, $date_db)
?>
</h2>

<table class=”month”>
<tr class=”days”>
<td>Mon</td>
<td>Tues</td>
<td>Wed</td>
<td>Thurs</td>
<td>Fri</td>
<td>Sat</td>
<td>Sun</td>
</tr>
<?php

$today = date(“d”, $date_db); // Current day
$month = date(“m”, $date_db); // Current month
$year = date(“Y”, $date_db); // Current year

//die($today);
/*
$today = date(“d”); // Current day
$month = date(“m”); // Current month
$year = date(“Y”); // Current year
*/

$days = cal_days_in_month(CAL_GREGORIAN,$month,$year); // Days in current month

$lastmonth = date(“t”, mktime(0,0,0,$month-1,1,$year)); // Days in previous month

$start = date(“N”, mktime(0,0,0,$month,1,$year)); // Starting day of current month
$finish = date(“N”, mktime(0,0,0,$month,$days,$year)); // Finishing day of current month
$laststart = $start – 1; // Days of previous month in calander

$counter = 1;
$nextMonthCounter = 1;

//if the start day is greater than a Friday; if it is, we have 6 rows, otherwise we have 5
if($start > 5){ $rows = 6; }else {$rows = 5; }

//we then have a nested loop – one for the weeks, and one for the days in the weeks
for($i = 1; $i <= $rows; $i++){
echo ‘<tr class=”week”>’;
for($x = 1; $x <= 7; $x++){

if(($counter – $start) < 0){
$date = (($lastmonth – $laststart) + $counter);
$class = ‘class=”blur”‘;
echo ‘<td ‘.$class.’><a class=”date”></a></td>’;
}else if(($counter – $start) >= $days){
$date = ($nextMonthCounter);
$nextMonthCounter++;

$class = ‘class=”blur”‘;
echo ‘<td ‘.$class.’><a class=”date”></a></td>’;

}else {
$date = ($counter – $start + 1);
if($today == $counter – $start + 1){
$class = ‘class=”today”‘;
}
echo ‘<td ‘.$class.’><a class=”date”>’. $date . ‘</a></td>’;
}

$counter++;
$class = ”;
}
echo ‘</tr>’;
}

?>
</table>
</section>
[/code]

I’ve got it outputting one month so far but not organizing the items into it and not showing 5 months instead of one. Most of that code is from a tutorial. What I want to do is output 5 months (current and 4 in the future) and loop through items in my database and have PHP sort the items into the calendar. Any advice on where I go from here?

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @mongoose0031800 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...