PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
$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
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.
$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 );
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]