Jump to content

Need help with time


topflight

Recommended Posts

Hello so I am creating some what of a virtual airline script. And I would like a script that shows pilots who haven't done a flight within 30 days of their last flight and 20 days within their last flight.

 

I have a table called flights and everytime a pilot submit a flight report it insert the pilot name,login etc.. and the date of the flight.

 

I also have another table called members with just the pilot information in it passwords,etc... and last flight.

 

The last flight field is a date and so is date of flight. I need help create a script that shows all the pilots who haven't flown a flight 20 and 30 days within their last flight. And maybe 20 could be yellow and 30 or more can be red.

 

Please give me some examples or help on how I can start this. Thanks in advanced.

Link to comment
https://forums.phpfreaks.com/topic/199200-need-help-with-time/
Share on other sites

You can do it either in the mysql or in PHP.

 

If you want to do it in mysql, you can make your selects with the NOW() variable. Subtract date from NOW() and if it's greater than 30 or greater than 20 and less than 30.

 

If you do it in PHP, you can use the date() function to do something similar, just have a for loop for each row and do the check.

Link to comment
https://forums.phpfreaks.com/topic/199200-need-help-with-time/#findComment-1045524
Share on other sites

Topflight, it would be best if you could convert your dates into the standard yyyy-mm-dd. If not, you could always get the db result, break it into an array, then use that to compare:

 

$result = mysql_result("SELECT * FROM table ORDER BY date") or die(mysql_error());
for($i=0; $i < mysql_num_rows($result); $i++)
{
    $date = explode('.', mysql_result($result, $i, "date"));
    $date = $date[2].'-'.$date[1].'-'.$date[0];
    if(date('Y-m-d') - $date > 30)
    {
        echo 'Last flight was greater than 30 days';
    } elseif(date('Y-m-d')-$date > 20) { 
        echo 'Last flight was greater than 20 days, but less than 30';
    } else {
        echo 'Last flight was less than 20 days ago';
    }
    echo '<br /><br />';
}

 

I didn't test the above code, so your mileage may vary, but that would be the general idea.

Link to comment
https://forums.phpfreaks.com/topic/199200-need-help-with-time/#findComment-1045940
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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