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 8568157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:02:51+00:00 2026-06-11T18:02:51+00:00

I have a PHP code that generates a calendar. I’m trying to highlight the

  • 0

I have a PHP code that generates a calendar. I’m trying to highlight the current date in this following code:

<?php
require("aacfs.php");

define("ADAY", (60*60*24));

if ((!isset($_POST['month'])) || (!isset($_POST['year']))) {
    $nowArray = getdate();
    $month = $nowArray['mon'];
    $year = $nowArray['year'];
} else {
    $month = $_POST['month'];
    $year = $_POST['year'];
}
$start = mktime(12,0,0,$month,1,$year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title><?php echo "Calendar: ".$firstDayArray['month']." " . $firstDayArray['year']; ?></title>
</head>
<script type="text/javascript">
function eventWindow(url) {
    var width = 500;
    var height = 500;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    event_popupWin = window.open(url, "subWind", windowFeatures, "POS", 'event', 'resizable=yes,scrollbars=yes,toolbar=no,width=400,height=400');
    event_popupWin.opener = self;
}
</script>
<script type="text/javascript">

    function hiliteToday(){
        var nDate = new Date();
        nDate = nDate.getDate();
        var nTable = document.getElementById('currMonth');
        nRows = nTable.rows.length;
        nCells = nTable.rows[0].cells.length;
        for (i=0; i<nRows; i++)
            {
             for (n=0; n<nCells; n++)
                {
                 var tmp = nTable.rows[i].cells[n].innerHTML;
                 tmp = tmp.split("<");
                 if (tmp[0] == nDate){nTable.rows[i].cells[n].style.backgroundColor = 'cyan'}
                }

            }
    }

    window.onload=hiliteToday;

</script>
<body>
<h1><center>Select a Month/Year</center></h1>
<center><form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="month">
<?php
$months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

for ($x=1; $x<=count($months); $x++){
    echo "<option value=\"$x\"";
    if ($x == $month){
        echo " selected";
    }
    echo ">".$months[$x-1]."</option>";
}
?>
</select>
<select name="year">
<?php
for ($x=2012; $x<=2027; $x++){
    echo "<option";
    if ($x == $year){
        echo " selected";
    }
    echo ">$x</option>";
}
?>
</select>
<input type="submit" name="submit" value="Go">
</form></center>
<br />
<?php
$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<center><table border=\"1\" cellpadding=\"5\" id=\"currMonth\"><tr>\n";
foreach ($days as $day) {
    echo "<td style=\"background-color: #CCCCCC; text-align: center; width: 14%\">
          <strong>$day</strong></td>\n";
}

for ($count=0; $count < (6*7); $count++) {
    $dayArray = getdate($start);
    if (($count % 7) == 0) {
        if ($dayArray["mon"] != $month) {
            break;
        } else {
            echo "</tr><tr>\n";
        }
    }
    if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) {
        echo "<td>&nbsp;</td>\n";
    } else {
        $chkEvent_sql = "SELECT acode FROM reservation WHERE month(etd) = '".$month."' AND dayofmonth(etd) = '".$dayArray["mday"]."' AND year(etd) = '".$year."' ORDER BY etd";
        $chkEvent_res = mysql_query($chkEvent_sql) or die(mysql_error());

        if (mysql_num_rows($chkEvent_res) > 0) {
            $event_title = "<br/>";
            while ($ev = mysql_fetch_array($chkEvent_res)) {
                $event_title .= stripslashes($ev["acode"])."<br/>";
            }
            mysql_free_result($chkEvent_res);
        } else {
            $event_title = "";
        }

        echo "<td valign=\"top\"><a href=\"javascript:eventWindow('event.php?m=".$month."&d=".$dayArray["mday"]."&y=$year');\">".$dayArray["mday"]."</a><br/>".$event_title."</td>\n";

        unset($event_title);

        $start += ADAY;
    }
}
echo "</tr></table></center>";
mysql_close();
?>
</br><center><a href="javascript:self.close()"><font face="consolas"><b>Close</b></font></a></center>
</body>
</html>

but it doesn’t seem to work. The javasript function hiliteToday() is supposed to do work since I’m binding it in the <table id='currMonth'> but I don’t get any result. What am I doing wrong? Please help me. Thanks in advance!

EDIT: Here’s how the calendar looks like:

enter image description here

  • 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-11T18:02:53+00:00Added an answer on June 11, 2026 at 6:02 pm

    You are checking with if (tmp[0] == nDate), if the table cell has the current day. In example “21” for today.
    But you never set only days to your table cells.

    Change your 2nd for-loop to:

             for (n=0; n<nCells; n++)
                {
                 var tmp = nTable.rows[i].cells[n].innerHTML;
                 if (tmp.search(nDate)!=-1){nTable.rows[i].cells[n].style.backgroundColor = 'cyan'}
                }
    

    Your content of each cell is something like

    <a href="">DAYOFMONTH</a>Title
    

    You are splitting for “>” now, so you got your day of month in tmp[1]. With “search” you search in a string for an regular expression.

    EDIT:

    <script type="text/javascript">
    
        function hiliteToday(){
            var nDate = new Date();
            var sDate = nDate.getMonth()+1 + "_" + nDate.getDate();
            document.getElementById(sDate).style.backgroundColor = 'cyan';
        }
    
    window.onload=hiliteToday;
    
    </script>
    

    Change your PHP echo to:

    echo "<td id=\"".$month."_".$dayArray["mday"]."\" valign=\"top\"><a href=\"javascript:eventWindow('event.php?m=".$month."&d=".$dayArray["mday"]."&y=$year');\">".$dayArray["mday"]."</a><br/>asdas</td>\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some PHP code that generates a calendar and then outputs html to
I have this code (an example that PHP generates for me)... <select id=outsideBlue3> <option
I have this code that generates a WP menu: <div id=menu> <?php $args =
I have a php code that generates a piece of html code like this.
I have some PHP code that generates dynamic tables of data on the fly.
I have the following php code that gets a serialized array from a mysql
I have a line of php code that looks like this: echo <script>$('#edit_errors').html('<h3><em>Please Correct
I have a line of PHP code that does the following: $xml = <xml><request>...[snipped
I have a script that generates a csv file using the following code: header('Content-type:
I have some php code that generates multiple MySql queries and combines the results.

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.