Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:28:57+00:00 2026-06-15T19:28:57+00:00

I have this beautiful and versatile calendar script $giorno = isset($_GET[‘g’]) ? $_GET[‘g’] :

  • 0

I have this beautiful and versatile calendar script

$giorno = isset($_GET['g']) ? $_GET['g'] : date('Y-m-d');
$day = strtotime($giorno);
$today = date('Y-m-d', strtotime('today'));
$date = mktime(0, 0, 0, date("m", $day), 1, date("Y", $day));
$past = mktime(0, 0, 0, date("m", $date)-1, 1, date("Y", $date));
$future = mktime(0, 0, 0, date("m", $date)+1, 1, date("Y", $date));

$days = array("Domenica", "Lunedi", "Martedi", "Mercoledi", "Giovedi", "Venerdi", "Sabato");
$months = array("Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre");

$month = date("m", $date);
$year = date("Y", $date);

$day_offset = 1; //$day_offset % 7;
$start_day = mktime(0, 0, 0, $month, 1, $year); 
$start_day_number = date("w", $start_day);
$days_in_month = date("t", $start_day);

<table id="calendar">
<caption>
    <div class="left"><a href="<?php echo $phpSelf; ?>?g=<?php echo date('d/m/Y', $past); ?>" title="Mese precedente">‹</a></div>
    <div class="right"><a href="<?php echo $phpSelf; ?>?g=<?php echo date('d/m/Y', $future); ?>" title="Mese successivo">›</a></div>
    <div class="center"><?php echo $months[$month-1]; ?> <?php echo $year; ?></div>
</caption>
<tr>
<?php for ($x = 0; $x <= 6; $x++) { ?>
    <th scope="col"><?php echo substr(strtolower($days[($x+$day_offset)%7]), 0, 2); ?></th>
<?php } ?>
</tr>
<tr>
<?php
$blank_days = $start_day_number - $day_offset;
if ($blank_days < 0) { $blank_days = 7 - abs($blank_days); }
for ($x = 0; $x < $blank_days; $x++) {
?>
    <td>&nbsp;</td>
<?php } ?>
<?php for($x = 1; $x <= $days_in_month; $x++) { ?>
    <?php   if (($x + $blank_days-1) % 7 == 0){ ?>
    </tr>
    <tr>
    <?php } ?>
    <?php $day = $year . "-" . $month . "-" . leading($x); ?>
    <td><?php echo $x; ?></td>
<?php } ?>  
<?php while ((($days_in_month + $blank_days) % 7) != 0) { ?>
    <td>&nbsp;</td>
<?php   $days_in_month++;
}
?>
</tr>

It simply loops, given a day, through the entire month and draws a table calendar: so far so good
Now the tricky part: I have a recordset of events like this:

mysql_select_db($database_connArtesicilia, $connArtesicilia);
$query_rsEvents = "SELECT eventi.eve_id, eventi.eve_name, eventi.eve_from, eventi.eve_to FROM eventi WHERE eventi.eve_active";
$rsEvents = mysql_query($query_rsEvents, $connArtesicilia) or die(mysql_error());
$row_rsEvents = mysql_fetch_assoc($rsEvents);
$totalRows_rsEvents = mysql_num_rows($rsEvents);

I’d like to highlight the calendar cells (ie. with
<td class="highlight">) corresponding to events, and that would be not so difficult if events were limited to only one day… but some events span through multiple contiguous days (ie. from 5th to 8th december) and I have no idea how to highlight cells corresponding to 5, 6, 7 and 8

Please notice that database fields eve_from and eve_to are ALWAYS filled (if an event occur in only one day, dates are the same)
More, some events could overlap (ie. one from 5th to 8th and the other from 7th to 9th december): in an ideal world, I’d need both to simply highlight the cell if one or more events are present (for the small version of the calendar), and to list the event(s) of a cell (for the big version of the calendar)

Have you got some idea on how to achieve this?

Thanks in advance, as usual!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:28:58+00:00Added an answer on June 15, 2026 at 7:28 pm

    I’ve actually written a few calendar scripts in the past that dealt with this problem. One thing you might want to to do first is checkout how Google calendars handles this. It can be done purely with some js and css, but your existing PHP code makes it a bit of a kludge to work with.

    I can show you my old calendar class and how I approached the problem to help you out.

    Here’s a link to the code I used.

    It’s a simple class that uses DateTime objects to create a calendar very similar to yours. You can see how easy it would be to modify that code to include adding some events and highlighting them by simply checking that the event date lies within the given calendar day throughout each iteration.

    In fact, here, I took an extra 2 minutes to modify it myself and show you a working example.

    So the underlying problem you’re having is how you’re dealing with the dates. You’re suing timestamps and formatted dates and that’s making your logic a bit more tangly to work around.

    I strongly suggest using PHP’s DateTime class. It makes dealing with dates so much easier and abstract. You can see both the working example and code in that link where I’ve simply added two events to demonstrate how overlapping might be handled.

    We have 1 event set from Dec 12th, 2012 through Dec 16th, 2012, which is highlighted in green and another event set from Dec 15th, 2012 through Dec 21st, 2012 which is highlighted in red. Now, because the calendar is tiny I simply use non-breaking-spaced divs with a set background color in each cell. It’s not pretty but it gives you some idea to get you started.

    Feel free to use any of that code and I hope that helps. Cheers!

    P.S: I would strongly encourage you to switch away from ext/mysql mysql_* functions to interface with your mysql database in PHP and consider moving to the newer APIs such as PDO or MySQLi as ext/mysql is now deprecated and will be removed in future versions of PHP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this iPhone like checkbox script, which makes beautiful checkboxes. The code is
I have this beautiful jquery script that takes list of li s and groups
I have this xml <products> <product> <name>Demo</name> </product> <product> <name>Black Beauty III</name> <description>Beautiful les
Let's say I have an array like this: $array = array (this,is,me,and,I,am,an,array,hello,beautiful,world); How can
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
I have this script: http://jsfiddle.net/NV2uV/ It works, but I do not like it. Cons:
I have currently implemented this image slider http://www.dreamcss.com/2009/04/create-beautiful-jquery-sliders.html on a site but for some
I have this beautiful function, but I need to customize it to return just
Please have a look at this beautiful website : http://www.snipe.net/ If you are using
I have found this beautiful ggplot inspired color scheme for matplotlib and want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.