Jump to content

Recommended Posts

Since a lot of my pages have forms, and links, is there any way that I can combine these statements, as a way to save space, and code writing?

if(isset($_POST['date_month'])); 
switch($_POST['date_month']) {
     case '01': $pTitle = 'January'; break;
     case '02': $pTitle = 'Febuary'; break;
     case '03': $pTitle = 'March'; break;
     case '04': $pTitle = 'April'; break;
     case '05': $pTitle = 'May'; break;
     case '06': $pTitle = 'June'; break;
     case '07': $pTitle = 'July'; break;
     case '08': $pTitle = 'August'; break;
     case '09': $pTitle = 'September'; break;
     case '10': $pTitle = 'October'; break;
     case '11': $pTitle = 'November'; break;
     case '12': $pTitle = 'December'; break;
  }

if(isset($_GET['date_month'])); 
switch($_GET['date_month']) {
     case '01': $pTitle = 'January'; break;
     case '02': $pTitle = 'Febuary'; break;
     case '03': $pTitle = 'March'; break;
     case '04': $pTitle = 'April'; break;
     case '05': $pTitle = 'May'; break;
     case '06': $pTitle = 'June'; break;
     case '07': $pTitle = 'July'; break;
     case '08': $pTitle = 'August'; break;
     case '09': $pTitle = 'September'; break;
     case '10': $pTitle = 'October'; break;
     case '11': $pTitle = 'November'; break;
     case '12': $pTitle = 'December'; break;
  }

 

Thanks...

Link to comment
https://forums.phpfreaks.com/topic/63793-combining-_post-and-_get-statements/
Share on other sites

Thanks... This works perfect.

To combine month and year is this how it should be done:

	if(isset($_REQUEST['date_month'])) {
	$month = date("M",mktime(0,0,0,$_REQUEST['date_month']+1,0));
}
if(isset($_REQUEST['date_year'])) {
	$year = date("Y",mktime(0,0,0,$_REQUEST['date_year']+1,0));
}
$pTitle = ': '.$month.' '.$year;

 

or is there a better way?

using request is not good if you have the same index for the global variable like session post and get once you have the index x for get and post and you use request it will only get the last index or the value for the get or post might get over writen by one of the two

hope that helps

Depends really. If your always expecting both month and year to be passed together, use...

 

<?php

 if(isset($_REQUEST['date_month']) && isset($_REQUEST['date_year'])) {
   $pTitle = date("M Y",mktime(0,0,0,$_REQUEST['date_month']+1,$_REQUEST['date_year']));
 }

?>

using request is not good if you have the same index for the global variable like session post and get once you have the index x for get and post and you use request it will only get the last index or the value for the get or post might get over writen by one of the two

hope that helps

 

Im not 100% sure I follow your comment here. $_REQUEST has nothing at all to do with $_SESSION's. I understand the bit about get overiding post, but not sessions.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.