How to make countdown with record count

I am rebuilding a website with a sign-up form. There only 20 beds in a cabin available. In the signup form I want to show how many beds are available, counting down from 20 and stop showing the option when all beds are reserved. In mysql I used to do it with

<?php if ("".(20 - $countzwerf->TotalRows) ."" != "0") { // Show If ?> Ik wil een bedje in een zwervershut (+€ 10,00, nog <?php echo (20 - $countzwerf->TotalRows) ?> beschikbaar)<?php

} // ("".(20 - $countzwerf->TotalRows) ."" != “0”)

Do you somehow mark which beds are reserved? Or do you store them in another table?

They are stored in a table, and then counted like this:

<?php $countzwerversbed = new WA_MySQLi_RS("countzwerversbed",$baksorder_i,1); $countzwerversbed->setQuery("SELECT * FROM deelnemers WHERE overnachting = 'zwerversbed'"); $countzwerversbed->execute();?>

Which is the column you count?
I mean do you want to count how many are reserved already (and this is what you store in the db)?

Let me try to explain. When one books they choose how/where they will sleep. I option is called “zwerversbed”. When selected, tekst “zwerversbed” will be inserted in the field “overnachten”. I used to count the total records where “zwerversbed” was added (record count). I have a max numer of 20 “zwerversbedden”. So everytime someone adds “zwerversbed” to sleep, it is substracted from the number 20 (max. beds). When record count for “zwerversbed” <1 then the option “zwerversbed” will not be shown anymore.
I hope this makes any sense

Well then just use the dynamic attributes > display > show and for value use your query with a count filter applied to it.

That will show the number of beds booked. I would like to show the number of beds available e.g.

20 - {{}}

That is why asked you - are you storing somewhere which beds are reserved like in a column in the table or in another table? How do you mark the reserved ones?

The make a selection in the form for “zwervershut”. Then “zwervershut” is saved in the field “overnachting” in the dbasetabel. The count counts all mentions of “zwervershut” in the records and then comes up with a sum. That sum needs to be substracted from the number 20. Which will result in the total number of beds available. If the total number of beds available is 0, the “formselect” should be hidden, so only the alternatives will be available. under “overnachting”. I changed that part to English for better understanding.

If i understand you right, you just need a query, which is filtered by the word "zwerversbed" - filter the overnachting field.
Then on the page this query will show the reserved beds number using the count formatter.

Almost. I have that part working. I need to substract the number of reserved beds (now 1) from the available beds (20) to show the number of actual available beds.

It now says 1 available, but I want it to say 19 available (20 -/- 1)

Then substract the value of reserved bed from the value of total beds.

That was too easy. I don’t believe this. Getting more and more happy with Wappler. Just need to learn to think more simple. Have a good weekend.