I am working on a small project, creating a calendar based booking system which includes the following features: 1) A color coded key for Booked days, Available, Partly Booked, Off Days 2) Clickable days which open up a form with available time slots 3) When time slots selected another form which allows the user to enter details about the event and then book the day

I am using php, sql to complete the project. I am aware that there are scripts available online but i want to do this from scratch.

Stuck On
The code below is for a php calendar, above is what i need to achieve. Please can someone help me on how to complete this.

<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July", 
"August", "September", "October", "November", "December");
?>

<?php
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
?>

<?php
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];

$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;

if ($prev_month == 0 ) {
    $prev_month = 12;
    $prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
    $next_month = 1;
    $next_year = $cYear + 1;
}
?>

<table width="400" border="5" align="center">
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" align="left">  <a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td>
<td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a>  </td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" border="2" cellpadding="2" cellspacing="2">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF">
<strong> <?php echo $monthNames[$cMonth-1].' '.$cYear; ?> </strong>
</td>
</tr>
<tr>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
</tr>


<?php 
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
for ($i=0; $i<($maxday+$startday); $i++) {
    if(($i % 7) == 0 ) echo "<tr> ";
    if($i < $startday) echo "<td></td> ";
    else echo "<td align='center' valign='middle' height='20px'>". ($i - $startday + 1) . "</td> ";
    if(($i % 7) == 6 ) echo "</tr> ";
}
?>
</table>
</td>
</tr>
</table>

Recommended Answers

All 6 Replies

no one seems to be helping, as i think the whole question it too much..

**so can anyone help so can i make cell with a date clickable so i can display the form for that day using jquery? **

Wrong category you are posting... You need to go to 'Web Development' and then 'PHP'.

What is your current output by the way? And keep popping up form isn't a good idea because it is difficult to maintain. How about hover over a date and it display time available, then click on the date and it will tak you to booking form?

hi taywin, i am new to this how do i post move this to web development and then php???

i dont have any output atm, just a calendar which has previous and next buttons to go through the months.

your idea
"How about hover over a date and it display time available, then click on the date and it will tak you to booking form?"

how would i implement this?

Just some general PHP observations:

  1. PHP is an object-oriented language. Create appropriate classes, much like you would in Java or C++. Don't mix HTML output and PHP. It makes it very difficult to debug and is inefficient.
  2. If you have multiple adjacent PHP blocks, keep them in one. It makes stuff easier to read and analyze.
  3. Generate your HTML and/or Javascript in a class function, and only output to the client when done. This is relevate to the efficiency comment in #1 above. Also, you can insert debugging output when developing that way and see the output on the page output, which you cannot if they are intermingled.

If you do this, then you will easily find your problems. I used this approach to adapt some complex PHP + HTML + Javascript code for my previous employer. We needed to add functionality (lots of graphs, colors, side/bottom labels, user-selectable options, etc) and with the original code that was impossible. I refactored the code into PHP classes and it became trivial to enhance the product and debug it at the same time!

<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July", 
"August", "September", "October", "November", "December");
?>

<?php
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
?>

<?php
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];

$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;

if ($prev_month == 0 ) {
    $prev_month = 12;
    $prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
    $next_month = 1;
    $next_year = $cYear + 1;
}
?>
/.. use this code it will fix your problems .../
thank you

/full code for calender/

   <?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
    "August", "September", "October", "November", "December");
?>

                            <?php
                            if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
                            if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
                            ?>

                            <?php
                            $cMonth = $_REQUEST["month"];
                            $cYear = $_REQUEST["year"];

                            $prev_year = $cYear;
                            $next_year = $cYear;
                            $prev_month = $cMonth-1;
                            $next_month = $cMonth+1;

                            if ($prev_month == 0 ) {
                                $prev_month = 12;
                                $prev_year = $cYear - 1;
                            }
                            if ($next_month == 13 ) {
                                $next_month = 1;
                                $next_year = $cYear + 1;
                            }
                            ?>
                            <div id="calendar_div" name="calendar_div">
                                <table >
                                    <tr>
                                               <td >&nbsp;&nbsp;<a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF"> < </a>
                                                  <a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF"> > </a>&nbsp;&nbsp;</td>
                                                </tr>
                                            </table>
                                          <h2 style="color: #ffffff" >  <?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></h2>
                                            <table class="table" style="border: 0">

                                                <tr>
                                                    <td  style="color:#FFFFFF"><strong>Sun</strong></td>
                                                    <td   style="color:#FFFFFF"><strong>Mon</strong></td>
                                                    <td  style="color:#FFFFFF"><strong>Tue</strong></td>
                                                    <td  style="color:#FFFFFF"><strong>Wed</strong></td>
                                                    <td  style="color:#FFFFFF"><strong>Thr</strong></td>
                                                    <td  style="color:#FFFFFF"><strong>Fri</strong></td>
                                                    <td  style="color:#FFFFFF"><strong>Sat</strong></td>
                                                </tr>

                                                <?php

                                                $timestamp = mktime(0,0,0,$cMonth,1,$cYear);
                                                $maxday = date("t",$timestamp);
                                                $thismonth = getdate ($timestamp);

                                                $startday = $thismonth['wday'];

                                                for ($i=0; $i<($maxday+$startday); $i++) {
                                                    if(($i % 7) == 0 ) echo "<tr>\n";
                                                    if($i < $startday) echo "<td></td>\n";

                                                    else echo "<td height='20px'>". ($i - $startday + 1) . "</td>\n";
                                                    if(($i % 7) == 6 ) echo "</tr>\n";
                                                }

                                                ?>

                                            </tr>
                                </table>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.