/    Sign up×
Community /Pin to ProfileBookmark

Table Formatting Help

I found this PHP/HTML calendar table on the internet:
[url]http://localhost/vcc/calendarPage.php[/url]

As you can see, whenever I have an event added the formatting for those days gets all screwed up and I can’t figure out why.

Here’s my PHP:

[CODE]
<?php
/* draws a calendar */

function draw_calendar($month,$year){
require(‘mysqli_connect.php’);

/* draw table */
$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>’;

//return $calendar;
//}

// days and weeks vars now …
$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();

// row for week one
$calendar.= ‘<tr class=”calendar-row”>’;

// print “blank” days until the first of the current week
for($x = 0; $x < $running_day; $x++)
{
$calendar.= ‘<td class=”calendar-day-np”>&nbsp;</td>’;
$days_in_this_week++;
}
$calendar .= ‘<script type=”text/javascript” >’;

$calendar .= ‘cookie_day_name = “dayCookie”;’;
$calendar .= ‘cookie_month_name = “monthCookie”;’;
$calendar .= ‘cookie_year_name = “yearCookie”;’;

$calendar .= ‘var localDay;’;
$calendar .= ‘var localMonth;’;
$calendar .= ‘var localYear;’;

$calendar .= ‘function putCookie(day, month, year) {‘;

$calendar .= ‘localDay=day;’;
$calendar .= ‘localMonth=month;’;
$calendar .= ‘localYear=year;’;

$calendar .= ‘document.cookie=cookie_day_name+”=”+localDay+”; expires=Thursday, 01-Sep-2016 05:00:00 GMT”;’;
$calendar .= ‘document.cookie=cookie_month_name+”=”+localMonth+”; expires=Thursday, 01-Sep-2016 05:00:00 GMT”;’;
$calendar .= ‘document.cookie=cookie_year_name+”=”+localYear+”; expires=Thursday, 01-Sep-2016 05:00:00 GMT”;’;
$calendar .= ‘}’;

$calendar .= ‘</script>’;
// keep going with days….
for($list_day = 1; $list_day <= $days_in_month; $list_day++)
{
$calendar.= ‘<td class=”calendar-day”>’;
// add in the day number
$calendar.= ‘<a href=”event.php” onclick=”putCookie(‘ . $list_day . ‘,’ . $month . ‘,’ . $year . ‘)”><div class=”day-number”>’.$list_day.'</div></a>’;

// QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !! IF MATCHES FOUND, PRINT THEM !!
//$calendar .= ‘<a href=”event.php” onclick=”putCookie(‘ . $list_day . ‘,’ . $month . ‘,’ . $year . ‘)”>Add Event</a>’;
$q = “SELECT eventName, fromDate FROM event WHERE YEAR(fromDate) = ‘$year’ AND MONTH(fromDate) = ‘$month’ AND DAY(fromDate) = ‘$list_day'”;

$r = mysqli_query($dbc, $q);
if($r)
$num = mysqli_num_rows($r);

$calendar .= str_repeat(‘<p>&nbsp;</p>’,3-$num);

if($num > 0 && $r)
{
while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
{
$calendar .= ‘<br /><a href=”#”>’ . $row[‘eventName’] . ‘</a>’;
}
}

$calendar.= ‘</td>’;
if($running_day == 6)
{
$calendar.= ‘</tr>’;
if(($day_counter+1) != $days_in_month)
{
$calendar.= ‘<tr class=”calendar-row”>’;
}
$running_day = -1;
$days_in_this_week = 0;
}
$days_in_this_week++; $running_day++; $day_counter++;
}

// finish the rest of the days in the week
if($days_in_this_week < 8)
{
for($x = 1; $x <= (8 – $days_in_this_week); $x++)
{
$calendar.= ‘<td class=”calendar-day-np”>&nbsp;</td>’;
}
}

// final row
$calendar.= ‘</tr>’;

// end the table
$calendar.= ‘</table>’;
mysqli_close($dbc);
// all done, return result
return $calendar;
}
?>
[/CODE]

And here’s my CSS:

[CODE]
/* calendar */
table.calendar { border-left:1px solid #999; }
tr.calendar-row { }
td.calendar-day { min-height:100px; font-size:10px; position:relative; } * html div.calendar-day { height:100px; }
#td.calendar-day:hover { background:#eceff5; }
td.calendar-day-np { background:#eee; min-height:120px; } * html div.calendar-day-np { height:120px; }
td.calendar-day-head { background:#ccc; font-weight:bold; text-align:center; width:80px; padding:5px; border-bottom:1px solid #999; border-top:1px solid #999; border-right:1px solid #999; }
div.day-number { background:#999; padding:5px; color:#fff; font-weight:bold; float:right; margin:-5px -5px 0 0; width:10px; text-align:center; }
div.day-number:hover {background: blue;}
/* shared */
td.calendar-day, td.calendar-day-np { width:80px; padding:5px; border-bottom:1px solid #999; border-right:1px solid #999; }
#center {text-align: center;
margin-top: 20px;}
[/CODE]

to post a comment
HTML

1 Comments(s)

Copy linkTweet thisAlerts:
@mikeglazauthorSep 17.2011 — Nevermind, I figured it out.

mike
×

Success!

Help @mikeglaz 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 6.1,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...