There is a complex structure consisting of select and radiobutton. enter image description here
And the database: enter image description here
In this example, parking may not be provided or available for a fee or free of charge. Depending on the choice (paid / free / no), you can specify additional options (such as location, type, reservation, etc.).
What is the best way to store such a structure in the database?
I see the solution of the problem in the form of a tree, I don’t know how true it is and I don’t know how to implement it correctly. If stored in the form of a tree, such records will be the sheets of such a tree: "Paid parking on the territory with the need for preliminary reservation at the price of 1000r / d", then it is not clear how to combine several select into one.

  • one
    Is it necessary to complicate things like that? Judging by the image, most of the data is repeated for different types. It is quite possible to store everything in one table. - GreyGoblin
  • NOSQL? In fact, you are trying to build it over SQL. - Sergey Rufanov
  • And what is your database? - D-side
  • While I use SQLite (while I study) then on PostgreSQL - Pavel

1 answer 1

Hello.

It’s better for you to decide, and you’ll understand it over time.

I would start simple, like this: enter image description here

This is an example, and:
business - Business centers
parking - Parking (generally the entire list)
location - Location (if parking is an LLC, then it has several places)
types - Type (private / municipality / bezhoznaya - you can make ENUM)
booking - booking (booking methods)

Paid not paid defines the paid field (1 paid, 0-no).
Create zero variants everywhere.
If someone tells you if there is another option not to create null records, leaving a connection, I will be a grateful.
We select all business centers and select the parking with WHERE parking_id>0 by LEFT JOIN parking .
And if there is a record, then there is parking, and further analysis went.

I do not pretend to THE BEST , but I myself would start with this.

UPD1
By the way, location can be infused into business .
On the other hand, it is not worth it, all of a sudden there is parking across the road, and a person is traveling through the navigator, then the coordinates should be exactly the parking spaces, and not the business center itself.

UPD2
It should also be noted that a BC may have several parking lots.
Therefore, it is better to make the connection MANY-KO-MANY : business <-> parking .
I apologize that not immediately, a good idea comes aposl ...

  • Thanks for the answer. The fact is that I want a universal method. Hotels have many different services (many to many). There are those that are simply provided and everything (this means there will be an entry in the link table "id: 1 hotel_id: 10 service_id: 120"), and there are such services that can be provided for a fee or for free and at the same time have their own settings (for example, parking) . And I would like to get a universal method for storing all services. - Pavel
  • Rename business to otels, and parking to services, I see no problem. In the linking table, you can not use id, but make otel_id+service_id as otel_id+service_id - borodatych
  • Good day! And tell me, please, what software do you use to display interconnections in the database as in the screenshot? - kover-samolet
  • My drawing was done with MySQL Workbench , the vehicle has supposedly phpMyAdmin - borodatych
  • I have dbdesigner.net - Pavel