How do i write an if else statement that depends on whether the page is being passed any variables? If none are passed i want to execute $strSQL5 = "SELECT distinct Training_Date from trainingattendance WHERE Training_Date between '".date('Y-m-')."01' and '".date('Y-m-')."31'"; but if the variable month is passed in the url header i need it to have that instead of the month please help Thanks
if (isset($_GET['month'])) { // Month has been passed in the URL... Do something... } else { // Do something else } PHP:
Assuming that the month is in the correct format, 01,02,03 etc... I would do something like: $date1 = date("Y-m-", mktime(0, 0, 0, (int)$_GET['month'], 1, date('Y'))).'01'; $date2 = date("Y-m-t", mktime(0, 0, 0, (int)$_GET['month'], 1, date('Y'))); $strSQL5 = "SELECT distinct Training_Date FROM trainingattendance WHERE Training_Date between '$date1' AND '$date2'"; PHP: