{"id":1801,"date":"2018-09-14T14:58:48","date_gmt":"2018-09-14T19:58:48","guid":{"rendered":"https:\/\/xlinesoft.com\/blog\/?p=1801"},"modified":"2022-10-07T18:37:26","modified_gmt":"2022-10-07T23:37:26","slug":"building-a-hotel-reservation-system","status":"publish","type":"post","link":"https:\/\/xlinesoft.com\/blog\/2018\/09\/14\/building-a-hotel-reservation-system\/","title":{"rendered":"Building a hotel reservation system"},"content":{"rendered":"<p>Lets say you run a mini-hotel and need to build a very simple reservation system. In this article we will show how avoid double-booking only showing the rooms that are available for selected date range. Similar approach can be applied to any other reservation system i.e. if you need to build conference rooms reservation app.<\/p>\n<p>In our database we need two tables, Rooms and Reservations. <\/p>\n<p><a href=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_1-300x218.png\" alt=\"\" width=\"300\" height=\"218\" class=\"alignnone size-medium wp-image-1803\" srcset=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_1-300x218.png 300w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_1-768x557.png 768w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_1-150x109.png 150w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_1-400x290.png 400w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_1.png 870w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><!--more--><\/p>\n<p>Rooms table simply stores a list of rooms.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_2.png\" alt=\"\" width=\"391\" height=\"181\" class=\"alignnone size-full wp-image-1811\" srcset=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_2.png 391w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_2-300x139.png 300w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_2-150x69.png 150w\" sizes=\"auto, (max-width: 391px) 100vw, 391px\" \/><\/p>\n<p>Each reservation is a record in Reservations table.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_3.png\" alt=\"\" width=\"518\" height=\"176\" class=\"alignnone size-full wp-image-1812\" srcset=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_3.png 518w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_3-300x102.png 300w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_3-150x51.png 150w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_3-400x136.png 400w\" sizes=\"auto, (max-width: 518px) 100vw, 518px\" \/><\/p>\n<p>We can see that if someone comes and tries to reserve a room for one night, September 14-15, they should only see rooms 17 and 33. Rooms 23 and 27 are already booked for these days. <\/p>\n<p>If we were to write this kind of select query manually this is how it supposed to look:<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_4.png\" alt=\"\" width=\"419\" height=\"278\" class=\"alignnone size-full wp-image-1806\" srcset=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_4.png 419w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_4-300x199.png 300w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_4-150x100.png 150w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_4-400x265.png 400w\" sizes=\"auto, (max-width: 419px) 100vw, 419px\" \/><\/p>\n<p>The only problem is that this query needs to be dynamic and needs to change based on DATEFROM and DATETO fields. SQL variables come to the rescue. In RoomID Lookup wizard we can use SQL variables in WHERE clause. This is how it is going to look:<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_45.png\" alt=\"\" width=\"684\" height=\"504\" class=\"alignnone size-full wp-image-1808\" srcset=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_45.png 684w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_45-300x221.png 300w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_45-150x111.png 150w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_45-400x295.png 400w\" sizes=\"auto, (max-width: 684px) 100vw, 684px\" \/><\/p>\n<p>And as a text that you can copy and paste to your project:<\/p>\n<pre name=\"code\" class=\"sql:nocontrols\">\r\nid not in ( select roomid from reservations where not\r\n\t (':dateto' < datefrom OR ':datefrom' > dateto) )\r\n<\/pre>\n<p>This is all the code you need. And it works the same way in PHPRunner, ASPRunner.NET and ASPRunnerPro. <\/p>\n<p>Here is how it looks in generated application:<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_5.png\" alt=\"\" width=\"702\" height=\"490\" class=\"alignnone size-full wp-image-1807\" srcset=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_5.png 702w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_5-300x209.png 300w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_5-150x105.png 150w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2018\/09\/scr_sql_vars_5-400x279.png 400w\" sizes=\"auto, (max-width: 702px) 100vw, 702px\" \/><\/p>\n<p>More about SQL variables:<br \/>\n<a href=\"https:\/\/xlinesoft.com\/phprunner\/docs\/sql_variables.htm\" rel=\"noopener noreferrer\" target=\"_blank\">PHPRunner manual<\/a><br \/>\n<a href=\"https:\/\/xlinesoft.com\/asprunnernet\/docs\/sql_variables.htm\" rel=\"noopener noreferrer\" target=\"_blank\">ASPRunner.NET manual<\/a><br \/>\n<a href=\"https:\/\/xlinesoft.com\/asprunnerpro\/docs\/sql_variables.htm\" rel=\"noopener noreferrer\" target=\"_blank\">ASPRunnerPro manual<\/a><\/p>\n<p>And here is the <a href=\"http:\/\/demo.asprunner.net\/kornilov_gmail_com\/Reservation\/reservations_list.php?a=return\" rel=\"noopener noreferrer\" target=\"_blank\">live demo project<\/a>. Go to Add Reservation page and play with dates to see how it works. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lets say you run a mini-hotel and need to build a very simple reservation system. In this article we will show how avoid double-booking only showing the rooms that are available for selected date range. Similar approach can be applied to any other reservation system i.e. if you need to build conference rooms reservation app. In our database we need two tables, Rooms and Reservations.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,8],"tags":[],"class_list":["post-1801","post","type-post","status-publish","format-standard","hentry","category-php-category","category-php-code-generator","category-tutorials"],"_links":{"self":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/1801","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/comments?post=1801"}],"version-history":[{"count":10,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/1801\/revisions"}],"predecessor-version":[{"id":2803,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/1801\/revisions\/2803"}],"wp:attachment":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/media?parent=1801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/categories?post=1801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/tags?post=1801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}