Author Topic: Daily / Weekly Flights  (Read 50 times)

Andy K

  • Newbie
  • *
  • Posts: 17
    • View Profile
Daily / Weekly Flights
« on: November 08, 2019, 05:10:16 PM »
Has anyone worked out a way to have a flights available only on certain days of the week at all?

Ta in advance!

drgullen

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: Daily / Weekly Flights
« Reply #1 on: November 08, 2019, 05:30:41 PM »
This isn't possible with the current version, but it wouldn't be too difficult to add if you're comfortable editing in PHP.

Andy K

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Daily / Weekly Flights
« Reply #2 on: November 08, 2019, 09:49:45 PM »
I'm happy enough with the database structure and locating / editing the files, already got the hang of doing making changes to the homepage and downloads etc. I'm not in any way, shape, or form
a programmer though so it's what lines of code I need to add that i'm not familiar with. I've tried a generic search on google but, maybe i'm not searching the right key words, i've not come up with anything so if you could point me in the right direction that would be handy :)

drgullen

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: Daily / Weekly Flights
« Reply #3 on: November 08, 2019, 10:53:44 PM »
Well, you'd have to add a new variable to the Routes table, probably one based on using the numeric value from the date function to represent the day of the week, which can be obtained like this: date("w").  That returns a value from 0 to 6, with 0 being Sunday through 6 being Saturday.

You'd have to edit the Administration panel where you enter the Routes to add this field, probably as a drop-down, so that this new variable in the Routes table gets populated.

Finally, you'd have to modify PHP on the website where you display the routes, comparing the day of week assigned to the route to today's day of the week, something like:

$sql = "select * from routes";
$db = new mysqli($db_host , $db_username , $db_password , $db_database);
$db->set_charset("utf8");
if ($db->connect_errno > 0) {
   die('Unable to connect to database [' . $db->connect_error . ']');
}
if (!$result = $db->query($sql)) {
   die('There was an error running the query [' . $db->error . ']');
}

while ($row = $result->fetch_assoc()) {
        $route_dayofweek = $row["route_day"];
        $today_dayofweek = date("w");

        if ($route_dayofweek == $today_dayofweek)  {

           (code to display the routes here)

        }
}

With code similar to this in place, the route only shows up on a specific day.  You could also use special values in that Routes table variable, like using a 7 perhaps would mean to display the route every day and maybe an 8 means display it on weekdays only.  You'd need additional code checking for that, of course.

You'd also have to similarly change the booking pages to make sure the routes are only bookable on those days as well.

I hope that helps you.

Andy K

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Daily / Weekly Flights
« Reply #4 on: November 08, 2019, 11:55:25 PM »
Certainly gives me a good starting point :) Thank you!

Andy K

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Daily / Weekly Flights
« Reply #5 on: November 09, 2019, 01:59:48 AM »
As an additional thought, would the same process work if I wanted to add an additional entry into the table (etc) to automate seasonal flights?

drgullen

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: Daily / Weekly Flights
« Reply #6 on: November 09, 2019, 05:05:25 AM »
If you're talking about displaying certain routes at certain times of the year, yeah basically the same type of logic would apply.  You'd need to add a display date to the Routes table and then add code to determine when to display those routes.

Andy K

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Daily / Weekly Flights
« Reply #7 on: November 16, 2019, 10:04:18 PM »
I assume, rather than a specific date, you could use a designation letter? S for summer etc.?

drgullen

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: Daily / Weekly Flights
« Reply #8 on: November 17, 2019, 02:33:13 AM »
Sure, you could have a range check of the date, such that if the date is between June 20 and September 20, display only the "S" routes, for example.