Hotel and training centre, Melksham, Wiltshire
High quality accommodation for course delegates, business travellers and the leisure visitor too.

Home Accessibility Bedrooms Book Here The Mouth Facebook Resources Find Us About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Rooms available tonight - how to code an algorithm from first principles

Delegates on Well House Consultants courses usually book 6 to 8 weeks ahead. Business guests at Well House Manor are usually booked a week or two ahead, and the leisure guests we have with us have normally given us good notice too. Telephone calls enquiring about rooms for the same night, mid-evening and later, are usually frustrating for us and for the enquirer, since we provide a full service - nice rooms and a place to stay and facilities, rather than just a bed for the night with a shared bathroom and loo. And that's typically what the late bookers really want, at a price to match the facilities.

However, there's another market out there - for the people who are booking a last minute staycation, or touring the area and booking during the day, and they're an excellent fit to our product.

Our hotel web site - until now - has shown availability for future dates and suggested people phone us up if they want to book and checkin on the same day. It's highlighted today's date in grey so that we can instantly know the date, and it's avoided late bookings through the automated system which we might not notice or might not have noticed in the past. But with our extended team, and our ever-heavier use of online booking, I've changed the system to offer rooms for the same night up to 8 p.m, and indeed to flag availability on the front of the Well House Manor web site for the current day. Examples screen captures here show yesterday's daytime display (we have 2 rooms available tonight), and the display as it was later in the evening.

A sort of change of topic ... One of the questions that comes up for newcomers to programming is "how do you decide to work it out and do it THAT way? And this requirement to add in a status for today's rooms is a good point from which to provide a simple answer.

Firstly, I look at the inputs and outputs required from the new logic - in this case variables that I will use in filling in the existing page template. And the outputs are:
  $ton - the message to display
  $tonk - the background colour behind the message
  $bklinkstart - the code to link (or not link) to the booking engine
  $bklinkend - matching code to end that link
The inputs are
  $tonight - rooms free tonight
  $tonlink - a link to a page to book for tonight
  the system's date() function to tell me the current hour number

Then I start separating out the cases. I have chosen to go for a default, offering the visitor a red panel and saying "full" unless there are conditions which mean otherwise, which I identify with if statements and then override my already-defaulted output variables in the conditional block. Let me show you the actual code - in PHP


  <?php
  
  # set up defaults
  
  $ton = "Sorry - Full Tonight<br /><br />Please book for future nights by selecting your arrival date below.";
  $tonk = "CC4400";
  $bklinkstart = "";
  $bklinkend = "";
  
  # Just one or more than one room - change colour and message
  
  if ($tonight == 1) {
    $ton = "Just 1 Room available tonight<br>[click here] to book";
    $tonk = "999900";
  }
  if ($tonight > 1) {
    $ton = "Rooms available tonight<br>[click here] to book";
    $tonk = "00CC00";
  }
  
  # If rooms available - add in a link
  
  if ($tonight > 0) {
    $bklinkstart = "<a href=https://lightning.he.net/~wellho/hotel/reservation.php?date_checkin1=$tonlink style=\"text-decoration:none;color: white;\">";
    $bklinkend = "</a>";
  }
  
  # If it's late in the day, supress the work done above and
  # put up a welcome for future nights
  
  if (date("H") > 19) {
    $ton = "Now closed for bookings<br>to stay tonight<br /><br />Please book for future nights by selecting your arrival date below.";
    $tonk = "000088";
    $bklinkstart = "";
    $bklinkend = "";
  }
  ?>


This is very much demonstration code in a spike solution form. I should have used a nested if to save a test and add robustness if rooms are available, for example, and I should probably call a function to set up links and use variables to hold colours.

Having written the code Testing is vital. The more possible conditions you have on your input data, the more tests are needed and you should test
• What happens is a value is LESS THAN a limit
• What happens is a value is GREATER THAN a limit, not forgetting
• TEST AT THE LIMIT too.
So I was running this code during the afternoon, late in the evening .. and also between 7 and 9 pm to make sure it flipped over properly. And on top of that, I created dummy settings (literally forced in different variables) to see what happened when availability dropped. We want to avoid any embarrassing overbookings at 'all costs' after all; we are fortunate that the site traffic is not high, and I could (and did) take the risk of it giving incorrect results for a few seconds while I did the tests - but on a busy site, that's absolutely something that could not be done and you would work with a copy of the script, or possibly a whole test environment which could be followed by quality assurance before it goes live (if you write your own testing schedule, you are likely to miss out the same condition in writing the tests as you did in forming the code!)

The example above is in PHP ... same thing applies to Python, which I'm training on in a couple of hours!

(written 2013-08-19, updated 2013-08-24)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
Q101 - Object Orientation and General technical topics - Programming Principles
  [2001] I have not programmed before, and need to learn - (2009-01-19)
  [2022] Pre and post increment - the ++ operator - (2009-02-03)
  [2228] Where do I start when writing a program? - (2009-06-11)
  [2310] Learning to write high quality code in Lua - (2009-07-30)
  [2327] Planning! - (2009-08-08)
  [2415] Variable names like i and j - why? - (2009-09-22)
  [2510] The music of the stock market - (2009-11-22)
  [2550] Do not copy and paste code - there are much better ways - (2009-12-26)
  [2586] And and Or illustrated by locks - (2010-01-17)
  [2737] Improving your function calls (APIs) - General and PHP - (2010-04-24)
  [2769] Easy - but for whom? - (2010-05-18)
  [2878] Program for reliability and efficiency - do not duplicate, but rather share and re-use - (2010-07-19)
  [2915] Looking up a value by key - associative arrays / Hashes / Dictionaries - (2010-08-11)
  [2964] An introduction to file handling in programs - buffering, standard in and out, and file handles - (2010-09-21)
  [3026] Coding efficiency - do not repeat yourself! - (2010-11-02)
  [3456] Stepping stones - early coding, and writing re-usable code quickly - (2011-09-24)
  [3542] What order are operations performed in, in a Perl expression? - (2011-12-07)
  [3548] Dark mornings, dog update, and Python and Lua courses before Christmas - (2011-12-10)
  [3551] Some terms used in programming (Biased towards Python) - (2011-12-12)
  [3673] Object oriented or structured - a comparison in Python. Also writing clean regular expressions - (2012-03-26)
  [3878] From Structured to Object Oriented Programming. - (2012-10-02)
  [3928] Storing your intermediate data - what format should you you choose? - (2012-11-20)
  [3954] Lesson 1 in programing - write clean, reuseable and maintainable tidy code - (2012-12-16)
  [4003] Web and console - same principle, same code - Ruby example - (2013-02-14)
  [4061] Seamless, integrated IT - we have a long way to go! - (2013-04-11)
  [4090] Test Driven Development in Python - Customer Comes First - (2013-05-16)
  [4118] We not only teach PHP and Python - we teach good PHP and Python Practice! - (2013-06-18)
  [4206] Writing the perfect program in Tcl? - (2013-11-13)
  [4325] Learning to program - what are algorithms and design patterns? - (2014-11-22)
  [4611] Hungarian, Camel, Snake and Kebab - variable naming conventions - (2016-01-03)
  [4632] Remember to ask the question before you listen for the answer - (2016-01-26)
  [4645] What are callbacks? Why use them? An example in Python - (2016-02-11)

M102 - Well House Manor - booking system
  [864] Add to shopping cart - NO VACANCIES sign - (2006-09-13)
  [1084] Writing terms and conditions for conferences and other events - (2007-02-17)
  [1311] What do people look for on a hotel web site? - (2007-08-20)
  [1554] Online hotel reservations - Melksham, Wiltshire (near Bath) - (2008-02-24)
  [1815] Hotel Guest Surveys - (2008-09-28)
  [1907] Melksham Hotel Rates - (2008-11-25)
  [2377] Wiltshire / Melksham Weddings - guest accommodation - (2009-08-26)
  [2403] Hotel Booking Scam / Cost of calls to 070 numbers - (2009-09-12)
  [2436] Melksham Hotel Rooms - pictures - (2009-10-04)
  [2705] Hotel booking in Melksham made easy! - (2010-04-03)
  [3281] Does Well House Manor Hotel in Melksham offer lots of discounts? - (2011-05-07)
  [3825] Well House Manor - direct hotel bookings help us improve the customer experience - (2012-08-04)
  [3932] River nearly bursting its banks in Melksham - (2012-11-23)
  [3976] Easy pricing, quick and easy checkout - (2013-01-15)
  [4122] Well House - booking through agents - (2013-06-23)
  [4138] Should a hotel accept guests who book for just one night? - (2013-07-11)
  [4144] Getting the best hotel rates - customer and hotelier viewpoints - (2013-07-27)
  [4232] Not wanted here - hotel guests who will not be happy - (2013-12-30)


Back to
Why are bus fares so high?
Previous and next
or
Horse's mouth home
Forward to
August Bank Holiday - day out from Melksham to London or Weymouth
Some other Articles
Wedding Photos - Kim Ellis to Kyle Londors, 22nd August 2013
A further chance to see Melksham on TV
Wedding Reception preps at Well House Manor
August Bank Holiday - day out from Melksham to London or Weymouth
Rooms available tonight - how to code an algorithm from first principles
Why are bus fares so high?
Tell me a bit about Melksham
Melksham Regular Public Transport Map - as at August 2013
Bus changes to Bath - good idea, but I despair at information available
Special General Meeting, Adoption of Constitution for TransWilts Community Rail Partnership
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page
Hello. I'm Graham Ellis. If you have a question about the hotel, please ask me or

 

then book here

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.info/mouth/4153_Roo ... iples.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb