PHP Calendar Issues -


i have following code created generate calendar, has issues:

//labels $daylabels          = array("monday","tuesday","wednesday","thursday","friday","saturday","sunday"); $monthlables        = array("january","february","march","april","may","june","july","august","september","october","november","december");  //max values $maxdays                = 7; $maxmonths          = 12;  //stats $forcemonth             = $_get['m']; $forceyear          = $_get['y'];  $todaydate          = date("d-m-y"); $todaydate          = date("d-m-y", strtotime($todaydate)); $explodetoday       = explode("-", $todaydate);  $currentday         = $explodetoday[0];  if(isset($forcemonth)) {     $currentmonth   = $forcemonth; } else {     $currentmonth   = $explodetoday[1]; };  if(isset($forceyear)) {     $currentyear        = $forceyear; } else {     $currentyear        = $explodetoday[2]; };  $daysinmonth        = cal_days_in_month(cal_gregorian, $currentmonth, $currentyear);  //database values $startdate          = array("01-06-2015","25-06-2015"); $enddate                = array("05-06-2015","05-07-2015"); $bookeduser         = array("dexter","james");  //counters $daysintomonth      = 0; $daycounter         = 0;  //debug echo '<p>current month: ' .$monthlables[$currentmonth-1]. ' / ' .$currentmonth. '</p>'; echo '<p>current year: ' .$currentyear. '</p>';  //start of calendar echo '<table>';  //print days of week echo '<tr>'; foreach($daylabels $day) {     echo '<td style="border-bottom:dashed 1px #ddd;">' .$day. '</td>'; }; echo '</tr>'; while($daysintomonth < $daysinmonth) {     //days month     $daysintomonth++;     $temp_inmonth           = sprintf("%02d", $daysintomonth);     $daysintomonth      = $temp_inmonth;      //days week     $daycounter++;     $temp_daycounter    = sprintf("%02d", $daycounter);     $daycounter             = $temp_daycounter;      //current calendar date     $caldate                    = date('d-m-y', strtotime($daysintomonth. '-' .$currentmonth. '-' .$currentyear));     $timecal                    = strtotime($caldate);      if($daycounter == 1) {         echo '<tr>';     };      if($startkey = array_search($caldate, $startdate) !== false) {         $booked = true;     };      if($endkey = array_search($caldate, $enddate) !== false) {         $booked = false;     };      if($booked == true) {         echo '<td style="background-color:red;">' .$caldate. ' / ' .$daysintomonth. ' ' .$daycounter. '</td>';     } else if($booked == true && array_search($caldate, $startdate) !== false) {         echo '<td style="background-color:red;">' .$caldate. ' / ' .$daysintomonth. ' ' .$daycounter. '</td>';     } else if($booked == false && array_search($caldate, $enddate) !== false) {         echo '<td style="background-color:red;">' .$caldate. ' / ' .$daysintomonth. ' ' .$daycounter. '</td>';     } else {         echo '<td>' .$caldate. ' / ' .$daysintomonth. ' ' .$daycounter. '</td>';     }      if($daycounter == $maxdays) {         echo '</tr>';         $daycounter = 0;     }; };  //table kill echo '</table>'; 

the issues have noticed:

  1. unable put $bookeduser respective $startdate,$enddate.
  2. when booking laps on month, skips dates until $enddate.
  3. all months start on monday, how go making them start of correct days of week.

possible code examples me solve issues great, in advance.

edit:

i have solved problem 3 using following code:

$firstdayofmonth    = strtotime("01-$currentmonth-$currentyear"); $firstdayofmonth    = date("d", $firstdayofmonth); $firstdayofmonth    = array_search($firstdayofmonth, $dayminilabels); $firstdayofmonth    = $firstdayofmonth + 1;  $startmonth         = 0;  if($firstdayofmonth != 7) {     while($startmonth < $firstdayofmonth) {         echo '<td></td>';         $startmonth++;         $daycounter++;         $temp_daycounter    = sprintf("%02d", $daycounter);         $daycounter             = $temp_daycounter;      }; }; 

for days , months (problem 3), this:

$todaysnumber = date('w'); $currentdayintext = $daylabels[$todaysnumber]; 

and same monhts.

mostly, in mysql-tables, dates placed 2015-06-05 , not in european time notation. maybe solve problem 1?


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -