doulangchao8934 2010-10-14 14:17
浏览 31
已采纳

mySQL表关系还是只使用一个表?! 需要帮助php mysql

I'm trying to create a drop down select option using PHP, MySQL, and ajadx I have the PHP and ajax pretty much figured out but I'm stumped on how I should organize my tables I couldn't decide so I created it both ways:

The first way the tables are:

  • CourseTbl containing (CourseID*, and CourseName)
  • DateTbl, (DateID*, and DatesOffered(entered as a varchar unsure of how to do date to show two day span)
  • LocationTbl (LocationID*, LocationName)

I figured I could try and connect the ID's for each but realized there is no way to connect them since their are some that repeat dates and some that are offered the same daye.

I also have the a table which just lists all of these together.

TableSelect (ID*, CourseName, DatesOffered, LocationName*)

If I wanted to make it as a drop down select would I have to create a subID that would be and INNER Join? Use an XML with PHP? I just keep asking myself how can I input the information and query it properly?

How is the best way to attack this? any help would be great and thanks for your time!

  • 写回答

1条回答 默认 最新

  • dongshi6710 2010-10-14 14:28
    关注

    It probably would be beneficial for you to store all this data in a single table. The reason I say this is your queries would be a lot less intense (you are not joining on multiple tables) only doing a select from one table then and if you structure your data right you can use the output exactly as is to populate your dropdown boxes.

    An interesting methodology to follow is the one where you try to think of what you want to accomplish first and how the end result is going to look and work. Then you design your DB to accommodate you with this structure.

    I have found that if your DB structure is right and you serve your php script the data as it needs it, your site is amazingly scalable. I mean it makes sense to use a single select rather than a inner join on 3 tables right?

    You would also sit with one set of ID's and no foreign keys etc to keep data integrity. If I read your explanation right then I see the data relates exactly to each other and its always good to group the same data together.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line