Page 1 of 1

changing day of the month

Posted: Sun Oct 22, 2006 11:09 pm
by garry27
i have a calendar with two hyperlinks in it. one takes you to the next month, the other to the previous month. the code below performs this function but when it comes to changing the name of the month ('F') it ony returns a useless integer value.


Code: Select all

$month = $_GET['month'];
		$month_name = $_GET['month_name'];
		if ($month == '')  
		{
		$month = date("m");
		$month_name = date("F");
		}
    
    if ($month > 1) 
      $prevm = sprintf ( ' <a href="?month=%s&month_name=%s&year=%s" ><<</a> ', $month - 1, $month_name - 1, $year );
    else      //If it is January our prev link will be December of the previous year 
    $prevm = sprintf ( ' <a href = "?month=%s&month_name=%s&year=%s" ><<</a> ' , 12, $month_name - 1, $year - 1 ); 
    if ($month < 12) 
      $nextm = sprintf ( ' <a href="?month=%s&month_name=%s&year=%s" >>></a>', $month + 1, $month_name + 1, $year );
    else   //if it is December our next link will be January of the next year
      $nextm = sprintf( ' <a href="?month=%s&month_name=%s&year=%s" >>></a>', 1, $month_name + 1, $year + 1 );

how do i get it so it changes the string name of the current month and how do i make the top line to read "if no post value for 'month' was passed"? so it looks neater. i tried

Code: Select all

if (!$_POST['month'])
but it didn't work

thanks in advance!

garry

Posted: Sun Oct 22, 2006 11:49 pm
by John Cartwright
I'm not sure what you are asking, please rephrase.

As for

Code: Select all

if (!$_POST['month'])
Try using empty()

Code: Select all

if (empty($_POST['month'])) {
although I think you meant to use $_GET

Month name

Posted: Mon Oct 23, 2006 12:28 pm
by churt
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


"$month_name" is a text string and can't be used in calculation.  You are already passing the month number you want ("$month ").   Just reset the month name on the other end useing the month variable you passed.

Code: Select all

$month = $_GET['month'];
                $month_name = $_GET['month_name'];
                if ($month == '') 
                {
                $month = date("m");
                $month_name = date("F");
                }
    if ($month > 1)
      $prevm = sprintf ( ' <a href="?month=%s&month_name=%s&year=%s" ><<</a> ', $month - 1, $year );
    else      //If it is January our prev link will be December of the previous year
    $prevm = sprintf ( ' <a href = "?month=%s&month_name=%s&year=%s" ><<</a> ' , 12, $year - 1 );
    if ($month < 12)
      $nextm = sprintf ( ' <a href="?month=%s&month_name=%s&year=%s" >>></a>', $month + 1, $year );
    else   //if it is December our next link will be January of the next year
      $nextm = sprintf( ' <a href="?month=%s&month_name=%s&year=%s" >>></a>', 1, $year + 1 );
Somthing like:

Code: Select all

$month_name=date("F", mktime(0,0,0,$month);

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]