Reputation: 1185
Just a quick query on the best databased structure to go with for a small application, [ the database will be SqlLite or MySql and the app written in PHP if that helps]
Basically my issue is that entries will have many options and these will be likely to be added to and removed so editing the db structure is probably not the best idea. I am just wondering what the best way to store this options to the data base. In similar situations in the past I have achieved this by storing the data serialised or in JSON format to a table row, but I am wondering if this is the best option, any advice would be great.
The application is map based where a user can add/remove markers, the markers have types [ eg shop, school, hospital etc. ] the user can also add and remove types. In addition to this the use can create map views eg a map where only the school and hospitals are visible.
It is a bit hard to describe but here is a go describing the [ simplified ] table structure
markers
+---------+-----+-----+--------+-----------+
|markerID | lat | lng | typeID | name |
+---------+-----+-----+--------+-----------+
|1 | 52 | -9 | 1 | A School |
|2 | 52 | -9 | 2 | A Shop |
|3 | 52 | -9 | 1 | B School |
|4 | 52 | -9 | 3 | A Hospital|
+---------+-----+-----+--------+-----------+
marker types
+-------+-------------+--------------+
|typeID | name | icon |
+-------+-------------+--------------+
|1 | Schools | school.png |
|2 | Shops | shop.png |
|3 | Hospitals | hospitals.png|
+-------+-------------+--------------+
map view
+------+---------------------+---+
|mapID | name | ??|
+------+---------------------+---+
|1 | Schoool & Shops | ??|
|2 | Hospitals & Schools | ??|
+------+---------------------+---+
So my question is basically, what is the best way to store the information that mapID #42 should display markers with typeID #2, #5, and #23 for example.
Upvotes: 0
Views: 187
Reputation: 2146
You should use a third table which represents a relation between two tables:
mapView ---- < mapView-markerType > ---- markerType
mapView-markerType would have the attributes: | id | mapID | typeID |
(you should get a shorter name than mapView-markerType, obviously)
EDIT Considering the changes you made on the post, you would get:
mapView_markerType
id* | mapId | typeId
--------|----------|----------
1 | 1 | 1
2 | 1 | 2
3 | 2 | 1
4 | 2 | 3
EDIT2
So, to further explain what I meant on the comment below:
map view
+------+---------------------+----------+
|mapID | name | typeComb |
+------+---------------------+----------+
|1 | Schoool & Shops | {1,2} |
|2 | Hospitals & Schools | {1,3} |
+------+---------------------+----------+
Upvotes: 0
Reputation: 345
As i understand, the Map view could have many markers ( which is logic). so i think a join table would be the best solution. A table for example called MapMarkers that has the following structure : MapMarkers
| id | MapID | MarkersID | ?? | ( you can add other infos for example if you want to store personnalized maps for each client you can add userID)
Upvotes: 1