Jump to content

[SOLVED] function won't work


gish

Recommended Posts

this function when called will elevate the month or decrease the month depending on the link you press. I know what the issue is

 

date("m") +  $_SESSION //works fine

 

date("m") - $_SESSION  //this works very very badly

 

does anyone know how to fix it? =)

 

function GetMonth(){
		$Name = $_GET['m']; //this needs to be a session
    		switch($Name) {
        		case b: 
        		  $_SESSION ['calendar']--; 
  				  return mktime(0, 0, 0, 	date("m") - $_SESSION ['calendar'], date("d"), date("y"));
        		break;
        		case f: 
        		  $_SESSION ['calendar']++; 
			  return mktime(0, 0, 0, 	date("m") + $_SESSION ['calendar'] , date("d"), date("y"));
        		break;
       		default:
       		  $_SESSION ['calendar']= 0; 
   			  return mktime(0, 0, 0, 	date("m"), date("d"), date("y"));
   			}

}
echo date("d/m/Y", GetMonth()); 

Link to comment
https://forums.phpfreaks.com/topic/144178-solved-function-wont-work/
Share on other sites

hmmm.. this hard request

btw.. there an easy way.. but i think i should try your way

<?php
function GetMonth(){
         $Name = $_GET['m']; //this needs to be a session
          switch($Name) {
              case b:
                $_SESSION ['calendar']--;
                $res= mktime(0, 0, 0,    date("m") - $_SESSION ['calendar'], date("d"), date("y"));
              break;
              case f:
                $_SESSION ['calendar']++;
              $res=mktime(0, 0, 0,    date("m") + $_SESSION ['calendar'] , date("d"), date("y"));
              break;
             default:
               $_SESSION ['calendar']= 0;
              $res= mktime(0, 0, 0,    date("m"), date("d"), date("y"));
            }
         
    return $res;
}
echo date("d/m/Y", GetMonth()); 


?>

try this ^^ well..

$_SESSION ['calendar'] => is month?

<?php
function GetMonth(){
         $Name = $_GET['m']; //this needs to be a session
         $month1=$_SESSION ['calendar'];
         $month0=date("m");
          switch($Name) {
              case b:
                $month1--;
                $res= mktime(0, 0, 0, $moth0-$month1);
                //$res= mktime(0, 0, 0,    date("m") - $_SESSION ['calendar'], date("d"), date("y"));
              break;
              case f:
                $month1++;
                $res= mktime(0, 0, 0, $moth0+$month1);
                //$res=mktime(0, 0, 0,    date("m") + $_SESSION ['calendar'] , date("d"), date("y"));
              break;
             default:
               $_SESSION ['calendar']= 0;
               $res= mktime();//0, 0, 0,    date("m"), date("d"), date("y"));
            }

    return $res;
}

function getMonth1()
{
  $Name = $_GET['m']; //this needs to be a session
  $month1=$_SESSION ['calendar'];
  $month0=date("m");
  $month2=date('y')*12+date('m');
   switch($Name) {
              case b:
                $month1--;
                $res= month2-month1;
                //$res= mktime(0, 0, 0,    date("m") - $_SESSION ['calendar'], date("d"), date("y"));
              break;
              case f:
                $month1++;
                $res= month2+month1;
                //$res=mktime(0, 0, 0,    date("m") + $_SESSION ['calendar'] , date("d"), date("y"));
              break;
             default:
               $_SESSION ['calendar']= 0;
               $res= month2;//0, 0, 0,    date("m"), date("d"), date("y"));
            }
   $year1=floor($res / 12);
   $month3=($res%12) +1;

   return strtotime("$year1-$month3-".date(d));


}
echo date("d/m/Y", GetMonth());
echo date("d/m/Y", getMonth1());


?>

omg.. there no easy way.. hick.. sry..

my bad

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.