DBookatay Posted August 7, 2007 Share Posted August 7, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/63793-combining-_post-and-_get-statements/ Share on other sites More sharing options...
trq Posted August 7, 2007 Share Posted August 7, 2007 <?php if(isset($_REQUEST['date_month'])) { $pTitle = date("F",mktime(0,0,0,$_REQUEST['date_month']+1,0)); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/63793-combining-_post-and-_get-statements/#findComment-317933 Share on other sites More sharing options...
DBookatay Posted August 7, 2007 Author Share Posted August 7, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/63793-combining-_post-and-_get-statements/#findComment-317941 Share on other sites More sharing options...
teng84 Posted August 7, 2007 Share Posted August 7, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/63793-combining-_post-and-_get-statements/#findComment-317942 Share on other sites More sharing options...
trq Posted August 7, 2007 Share Posted August 7, 2007 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'])); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/63793-combining-_post-and-_get-statements/#findComment-317944 Share on other sites More sharing options...
trq Posted August 7, 2007 Share Posted August 7, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/63793-combining-_post-and-_get-statements/#findComment-317947 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.