简体   繁体   English

数据库表结构查询

[英]Database table structure query

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] 只需快速查询适用于小型应用程序的最佳数据库结构,[数据库将是SqlLite或MySql,并且如果有帮助,则使用PHP编写的应用程序]

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. 在过去的类似情况下,我已通过将序列化或JSON格式的数据存储到表行中来实现此目的,但是我想知道这是否是最佳选择,所以任何建议都很好。

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. 所以我的问题基本上是,存储信息的最佳方法是什么,例如mapID#42应该显示typeID#2,#5和#23的标记。

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 例如,名为MapMarkers的表具有以下结构: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)

You should use a third table which represents a relation between two tables: 您应该使用第三个表,该表代表两个表之间的关系:

mapView ---- < mapView-markerType > ---- markerType mapView ---- <mapView-markerType> ---- markerType

mapView-markerType would have the attributes: | mapView-markerType将具有以下属性: id | id | mapID | mapID | typeID | typeID |

(you should get a shorter name than mapView-markerType, obviously) (显然,您应该获得比mapView-markerType短的名称)

EDIT Considering the changes you made on the post, you would get: 编辑考虑到您对帖子所做的更改,您将获得:

mapView_markerType mapView_markerType

   id*    | mapId    | typeId
  --------|----------|----------
    1     | 1        | 1
    2     | 1        | 2
    3     | 2        | 1
    4     | 2        | 3

EDIT2 编辑2

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}   |
+------+---------------------+----------+

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM