Note that there are some explanatory texts on larger screens.

plurals
  1. POReservation system - Available tables
    primarykey
    data
    text
    <p>I've been working on this for a few days and I can't figure it out. Ill hope you can help me out.</p> <p>I'm working on a reservation system, I would like to check if there are table's availbe on DATE and TIME. This is how my database looks like.</p> <p><img src="https://i.stack.imgur.com/vbZ9V.png" alt="enter image description here"></p> <p>I would like to put the available tables into a select dropdown menu, so on the website it only shows available tables.</p> <p>If I use the following query I can get the reserverd tables</p> <pre><code>SELECT res.reserveringsnr, datum, begintijd, eindtijd, tafr.tafelnr FROM reserveringen AS res INNER JOIN tafels_regel AS tafr ON res.reserveringsnr = tafr.reserveringsnr WHERE (res.datum = "2013/12/18" AND (res.begintijd BETWEEN "12:00:00" and "14:00:00")) </code></pre> <p>So that query put's out the reserverd table's, but here's where I'm stuck. I have no idea how to check if a certain table is reserverd on DATE and TIME.</p> <p>(NOTE: The date and time will be filled in by an variable, but for the example I used just text)</p> <h2>Edit: Working on @sebt his solution</h2> <p>First of all, to answer your questions</p> <ol> <li>Reservations are always on the same day</li> <li>A reservation has a fixed time, 2 hours always.</li> </ol> <p>I've edited sebt's his query to my values:</p> <pre><code> SELECT t.* FROM tafels t LEFT JOIN (SELECT tafelnr FROM tafels_regel tf INNER JOIN reserveringen res ON tf.reserveringsnr=res.reserveringsnr WHERE res.datum="2012/01/12" AND res.begintijd&lt;"19:00:00" AND res.eindtijd&gt;"21:00:00" ) ReservationsAtThisTime ON t.tafelnr=ReservationsAtThisTime.tafelnr WHERE ReservationsAtThisTime.tafelnr IS NULL </code></pre> <p>This query output's the following result <img src="https://i.stack.imgur.com/tbBV1.png" alt="enter image description here"></p> <p>As you can see, the query results shows all tafels (12). </p> <p>I've also exported the tables reserveringen, tafels_regel and tafels to an .csv (see edited .csv below)</p> <h2>EDIT 2:</h2> <p>Well I've edited my query again, it works for a part. This is the query (<a href="http://s9.postimage.org/i35e5bin3/querryryryreyry.png" rel="nofollow noreferrer">Screenshot</a>)</p> <pre><code> SELECT t.* FROM tafels t LEFT JOIN (SELECT tafelnr FROM tafels_regel tf INNER JOIN reserveringen res ON tf.reserveringsnr=res.reserveringsnr WHERE res.datum="2013/01/12" AND res.begintijd &lt;= "19:00:00" AND res.eindtijd &gt;= "21:00:00" ) ReservationsAtThisTime ON t.tafelnr=ReservationsAtThisTime.tafelnr WHERE ReservationsAtThisTime.tafelnr IS NULL </code></pre> <p>There are 2 reservations on 2013/01/12. (<a href="http://nivali.com/reserverings_systeem.csv" rel="nofollow noreferrer">Download</a> edited .csv)</p> <p>Reservation 1: from 19:00 to 21:00 on tafel 1</p> <p>Reservation 2: from 20:00 to 22:00 on tafel 11 and tafel 12</p> <p>When I run the query above, the only tafel not showing is tafel 1, since tafel 1 is reserverd from 19:00 till 21:00. But however, from 20:00 till 22:00 tafel 11 and 12 are also reserverd. </p> <p>As you can see in the query results, only tafel 1 is reserverd. But when I would make another reservervation from 19:00 till 21:00 and I'm checking for available tafels, then tafel 11 and tafel 12 still shows. </p> <p>The tafel will be free at 19:00, that's right, but since we always sit 2 hours we can't sit there. </p> <p>Thanks again @sebt for your input, ill hope you can help me further with this query!</p> <h2>Problem solved</h2> <p>Thanks for all the help, this is the final query</p> <pre><code>SELECT t.* FROM tafels t LEFT JOIN (SELECT tafelnr FROM tafels_regel tf INNER JOIN reserveringen res ON tf.reserveringsnr=res.reserveringsnr WHERE res.datum="2013/01/12" AND res.eindtijd &gt; "19:00:00" AND res.begintijd &lt; "21:00:00" ) ReservationsAtThisTime ON t.tafelnr=ReservationsAtThisTime.tafelnr WHERE ReservationsAtThisTime.tafelnr IS NULL </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload