设计我的 MySQL 数据库以对不同日期的事物进行评级
我最近一直在使用 Reddit 作为我的帮助,它们非常棒,但后来我发现了这个网站,并觉得这是一个更适合提出问题的地方。希望乐于助人的趋势在这里继续下去。首先我要说的是,考虑到我以前从未做过类似的事情,我知道这个项目非常密集,但这并没有改变我正在做的事实并且我愿意学习如何做。
我正在设计一个网站,其中将展示我所在城市的酒吧和特色餐饮。用户将能够登录,主页将显示排名前 5 的酒吧特价/欢乐时光,以及当天(即周一、周二等)排名前 5 的餐饮特价/欢乐时光。每个“特别”都会有一个上下评级,供用户提供对特别的意见。
酒吧页面将列出当天的所有酒吧及其特色菜,以及对特色菜投赞成票或反对票的选项。餐饮页面也是如此。从那里,人们可以点击酒吧名称,进入专门关于该酒吧的页面。该页面将显示整周的特价商品。
我现在正在 phpmyadmin 中设计 MySQL 表,因为在编写设计的 html 和 css 后,这似乎是我需要开始的地方。我尝试过在谷歌上搜索一个可以构建的框架,但是我没有找到任何相关的内容。
最好在每个数据库下为一周中的每一天创建单独的表,将所有内容放入一个表中,或者完全采用另一种方式。这是我到目前为止所做的,让我知道我是否走在正确的轨道上。谢谢一百万! !(http://dl.dropbox.com/u/16887445/Screen%20shot%202011-07-06%20at%208.01.10%20PM.png)
I've been using reddit as my help recently, and they've been great but then I found this site and feel it's a much more appropriate place to ask my questions. Hopefully the helpfulness trend continues here. Let me start by saying I know this project is pretty intensive considering I have never done anything like it before, however that doesn't change the fact that I am doing it and I am willing to learn how.
I am designing a website which will feature the the bar and dining specials for my city. Users will be able to log on, and the home page will display the top 5 rated bar specials/ happy hours, and the top 5 dining specials/happy hours for that day(i.e. monday, tuesday, etc.). Each "special" will have an up down rating for the user to give their input on the special.
A bar page will list all of the bars and their specials for that day, and the option to upvote or downvote the special. Same thing with a dining page. From there, the person can click on the bar name to be taken to a page specifically about that bar. That page will show the specials for the entire week.
I'm in the process of designing the MySQL table now in phpmyadmin, as it seems like that's where I need to start after having written the html and css for the design. I've tried googling for a framework that I could build off of, however I didn't come up with anything relevant.
Would it be best to make separate tables under each database for each day of the week, put everything into one table, or another way entirely. This is what I made so far, let me know if I am on the right track or not. Thanks a million!
!(http://dl.dropbox.com/u/16887445/Screen%20shot%202011-07-06%20at%208.01.10%20PM.png)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
星期几是“特价”记录的一个属性,而不是记录本身。想象一下——如果你每天只有一张桌子,并且你想获得一个酒吧一周的所有特价,你将不得不进行七个查询:(
希望)这显然是一个糟糕的设计。您想要做的是能够通过一个查询来完成此操作:
另请注意,您甚至并不真正关心存储星期几,您需要的只是日期(无论如何您都需要),从中您可以提取一周中的某一天。我会创建一个类似这样的架构:
因此,要显示“我的酒吧”的特价商品,您可以执行以下操作:
显示周一排名前五的特价商品:
Day of the week is an attribute of a "specials" record, not a record unto itself. Picture this -- if you have one table per day, and you want to get all specials for one bar for a week, you'll have to make seven queries:
This is (hopefully) obviously a bad design. Whay you want is to do be able to do it with one query:
Note also that you don't even really care about storing the day of the week, all you need is the date (which you need anyway), from which you can extract day of the week. I'd create a schema something like this:
So, to display the specials for "My Bar", you do something like:
To display the top five rated specials for Monday:
如果我正确理解您的目的,这可能就是我设计架构的方式:
将数据标准化后,您可以使用查询或视图来提取聚合数据。例如,要查找特价商品的所有赞成票,您可以使用如下查询:
If I understand what you're going for correctly, this is probably how I'd design the schema:
Once you have the data normalised, you can use queries or views to pull the aggregated data. For example, to find all the up votes for a special, you could use a query like this: