Jump to content

Calender question


justinh

Recommended Posts

I want to add a backward and forward button to cycle through the months.. how would i go about this?

 

<?php
$date = time();
$day = date('d',$date);
$month = date('m',$date);
$year = date('y',$date);
$firstday = mktime(0,0,0, $month, 1, $year);
$title = date('F', $firstday);
$dayofweek = date('D', $firstday);
switch($dayofweek){

    case "Sun":
    $blank = 0;
    break;
    case "Mon":
    $blank = 1;
    break;
    case "Tue":
    $blank = 2;
    break;
    case "Wed":
    $blank = 3;
    break;
    case "Thu":
    $blank = 4;
    break;
    case "Fri":
    $blank = 5;
    break;
    case "Sat":
    $blank = 6;
    break;
    }
    $daysinmonth = cal_days_in_month(0, $month, $year);
    echo "<table border=1 width=294>";
    echo "<tr><th colspan=7>$month - $year</th></tr>";
    echo"<tr><td width=42>S</td><td width=42>M</td><td width=42>T</td><td width=42>W</td><td width=42>T</td><td width=42>F</td>
    <td width=42>S</td></tr>";
    $daycount = 1;
    echo "<tr>";
    while ($blank > 0){
    echo "<td></td>";
    $blank = $blank-1;
    $daycount++;
    }
    $daynum = 1;
    while($daynum <= $daysinmonth){
    if ($daynum == $day){
    $processid = $month.$daynum.$year;
    echo "<td><font color=red><a href=\"process.php?date=$processid\"> $daynum</a> </font></td>";
    $daynum++;
    $daycount++;
    }
    else {
    echo "<td> <a href=\"process.php?date=$processid\">$daynum</a> </td>";
    $daynum++;
    $daycount++;
    if($daycount > 7){
    echo "</tr><tr>";
    $daycount = 1;
    }
    }
}
while($daycount >= 1 && $daycount < 7){
  echo "<td></td>";
  $daycount++;
  }
  echo "</tr></table>";
  ?>
  

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/130768-calender-question/
Share on other sites

well i am trying to make a forward and backward arrow to cycle threw the months, but im a little new to php

 

i wrote this function but nothing happens when i click on the arrows. thanks in advance!

 

<?php
function nav($month){

if (!isset($_GET['direction'])){

} else {

if($_GET['direction'] = forward){

$month++;

} else {

$month--;
}}}



$date = time();
$day = date('d',$date);
$month = date('m',$date);
nav($month);
$year = date('y',$date);
$firstday = mktime(0,0,0, $month, 1, $year);
$title = date('F', $firstday);
$dayofweek = date('D', $firstday);

switch($dayofweek){

    case "Sun":
    $blank = 0;
    break;
    case "Mon":
    $blank = 1;
    break;
    case "Tue":
    $blank = 2;
    break;
    case "Wed":
    $blank = 3;
    break;
    case "Thu":
    $blank = 4;
    break;
    case "Fri":
    $blank = 5;
    break;
    case "Sat":
    $blank = 6;
    break;
    }
    $daysinmonth = cal_days_in_month(0, $month, $year);
    echo "<table border=1 width=294>";
    echo "<tr><th colspan=7><a href=\"calender.php?direction=backward\"><</a> $month - $year <a href=\"calender.php?direction=forward\">></a></th></tr>";
    echo"<tr><td width=42>S</td><td width=42>M</td><td width=42>T</td><td width=42>W</td><td width=42>T</td><td width=42>F</td>
    <td width=42>S</td></tr>";
    $daycount = 1;
    echo "<tr>";
    while ($blank > 0){
    echo "<td></td>";
    $blank = $blank-1;
    $daycount++;
    }
    $daynum = 1;
    while($daynum <= $daysinmonth){
    $processid = $month.$daynum.$year;
    if ($daynum == $day){

    echo "<td><font color=red><a href=\"process.php?date=$processid\"> $daynum</a> </font></td>";
    $daynum++;
    $daycount++;
    }
    else {
    echo "<td> <a href=\"process.php?date=$processid\">$daynum</a> </td>";
    $daynum++;
    $daycount++;
    if($daycount > 7){
    echo "</tr><tr>";
    $daycount = 1;
    }
    }
}
while($daycount >= 1 && $daycount < 7){
  echo "<td></td>";
  $daycount++;
  }
  echo "</tr></table>";
  ?>
  

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/130768-calender-question/#findComment-678701
Share on other sites

Thanks for your reply. :)

 

I really don't understand any of that code and which part applies to my problem. I am still a beginner in PHP, but I really don't like to just copy and paste a code in and see if it fixes my problem. I did however make a step in the right direction i think with this function i made.

function is at the top

<?php
function NavigateCalender($month){

if (isset($_GET['direction'])){



switch($_GET['direction']){

    case "1":
    
    $month--;
    global $month = $month;
    echo $month;
    break;
    
    case "2":
    
    $month++;
    echo $month;
    

    break;
    }
    } else {
    }
    }
    
    





$date = time();
$day = date('d',$date);
$month = date('m',$date);
$year = date('y',$date);
$firstday = mktime(0,0,0, $month, 1, $year);
$title = date('F', $firstday);
$dayofweek = date('D', $firstday);
NavigateCalender($month);

switch($dayofweek){

    case "Sun":
    $blank = 0;
    break;
    case "Mon":
    $blank = 1;
    break;
    case "Tue":
    $blank = 2;
    break;
    case "Wed":
    $blank = 3;
    break;
    case "Thu":
    $blank = 4;
    break;
    case "Fri":
    $blank = 5;
    break;
    case "Sat":
    $blank = 6;
    break;
    }
    $daysinmonth = cal_days_in_month(0, $month, $year);
    echo "<table border=1 width=294>";
    echo "<tr><th colspan=7><a href=\"calender.php?direction=1\"><</a> $month - $year <a href=\"calender.php?direction=2\">></a></th></tr>";
    echo"<tr><td width=42>S</td><td width=42>M</td><td width=42>T</td><td width=42>W</td><td width=42>T</td><td width=42>F</td>
    <td width=42>S</td></tr>";
    $daycount = 1;
    echo "<tr>";
    while ($blank > 0){
    echo "<td></td>";
    $blank = $blank-1;
    $daycount++;
    }
    $daynum = 1;
    while($daynum <= $daysinmonth){
    $processid = $month.$daynum.$year;
    if ($daynum == $day){

    echo "<td><font color=red><a href=\"process.php?date=$processid\"> $daynum</a> </font></td>";
    $daynum++;
    $daycount++;
    }
    else {
    echo "<td> <a href=\"process.php?date=$processid\">$daynum</a> </td>";
    $daynum++;
    $daycount++;
    if($daycount > 7){
    echo "</tr><tr>";
    $daycount = 1;
    }
    }
}
while($daycount >= 1 && $daycount < 7){
  echo "<td></td>";
  $daycount++;
  }
  echo "</tr></table>";
  ?>
  

 

When I click on the arrow it echo's either 9 ( backward arrow ) or 11 (forward arrow)  // i used this for debugging

But it still doesn't update the calender with the new month. Also it only echo's the next month once.

 

Thanks in advance for the help :P

 

 

Justin

 

 

Link to comment
https://forums.phpfreaks.com/topic/130768-calender-question/#findComment-678775
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.