kamal213 Posted January 9, 2012 Share Posted January 9, 2012 Hi guys The scripty below is an appointment (event) calender which selects events from my db. If the day is today's date it colour of the date colomn is red, if the day is the appointment date the colour is grey (the style is link using css class). I was would like the script to be able to deal with multiple date i.e. if an event/appointment has a start and end date. Does anyone have an idea how I could modify the codes to select multiple dates in display them as normal. Thanks alot <?php //check to see if passing variable is set i.e. if true get day, month, year. if(isset($_GET['day'])){ $day = $_GET['day']; } else{ //Get today's date from the computer and put them in date, month, year $day = date("j"); } if(isset($_GET['month'])){ $month = $_GET['month']; } else{ $month = date("n"); } if(isset($_GET['year'])){ $year = $_GET['year']; } else{ $year = date("Y"); } //echo $day."/".$month."/".$year; //calender variable $currentTimeStamp = strtotime("$year-$month-$day"); //gets current month name $first_day = mktime(0,0,0,$month, 1, $year) ; $monthName = date("F", $first_day); //gets how many days are there in the current month $numDays = date("t", $currentTimeStamp); //variable to count cell in the loop $counter = 0; ?> <table width="1028" border="0" summary="APPOINTMENT Calender"> <tr> <td bgcolor="#EAEAE2"><input style="width:40px" type='button' value='«' name='previousbutton' onClick="goLastMonth(<?php echo $month . ", " . $year; ?>);"/></td> <td colspan="5" align="center"><?php echo $monthName.", ".$year; ?></td> <td bgcolor="#EAEAE2"><input style="width:40px" type='button' value='»' name='nextbutton' onClick="goNextMonth(<?php echo $month . ", " . $year; ?>);"/></td> </tr> <tr> <td width="50px" align="center" scope="col">Sun</td> <td width="50px" align="center" scope="col">Mon</td> <td width="50px" align="center" scope="col">Tue</td> <td width="50px" align="center" scope="col">Wed</td> <td width="50px" align="center" scope="col">Thu</td> <td width="50px" align="center" scope="col">Fri</td> <td width="50px" align="center" scope="col">Sat</td> </tr> <?php echo "<tr>"; //looping from 1 to the number of days in the month for($i = 1; $i < $numDays+1; $i++, $counter++){ //males a timestamp for each day in the loop $timeStamp = strtotime("$year-$month-$i"); //makes a check if it is 'day 1' if($i == 1){ //gets which day 'day 1' fall on $firstDay = date("w", $timeStamp); //makes a loop and makes a blank cell if it's not the first day for($j = 0; $j < $firstDay; $j++, $counter++){ //blank space echo "<td> </td>"; } } if($counter % 7 == 0){ echo "</tr><tr>"; } $monthstring = $month; $monthlength = strlen($monthstring); //day string get from $i loop $daystring = $i; $daylength = strlen($daystring); if($monthlength <= 1){ $monthstring = "0".$monthstring; } if($daylength <= 1){ $daystring = "0".$daystring; } $todaysDate = date("d/m/Y"); $dateToCompare = $daystring . '/' . $monthstring . '/' . $year; echo "<td align='center' "; if($todaysDate == $dateToCompare){ echo "class='today'"; }else{ $sqlcount = "select b_date from booked_appointment where b_date='".$dateToCompare."'"; $noOfEvent = mysql_num_rows(mysql_query($sqlcount)); if($noOfEvent >= 1){ echo "class='event'"; } } echo "><strong><p align='center'><a href='system_diary.php?&day=" . $daystring . "&month=" . $monthstring . "&year=" . $year . "&v=true'>".$i."</a></p></strong></td>"; } echo "</tr>"; ?> </table> Quote Link to comment Share on other sites More sharing options...
kamal213 Posted January 10, 2012 Author Share Posted January 10, 2012 Hi guys pls help if you need more info pls let me know Quote Link to comment Share on other sites More sharing options...
solanki_mahendra131 Posted January 30, 2012 Share Posted January 30, 2012 Hello, If you have start and end date, in your database fields then just change your query as following $sqlcount = "select b_date from booked_appointment where ('".$dateToCompare."' BETWEEN b_date_start AND b_date_end)"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.