php help

Discussion in 'PHP' started by red_fiesta, May 7, 2007.

  1. #1
    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
     
    red_fiesta, May 7, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    
    if (isset($_GET['month']))
    {
        // Month has been passed in the URL... Do something...
    }
    else
    {
       // Do something else
    }
    
    PHP:
     
    nico_swd, May 7, 2007 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    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:
     
    jestep, May 7, 2007 IP