I'm developing an application using PHP / SQL Server that needs to store information on graduates from tons of different academic programs, along with information on how many were employed after graduating... This will then be queried by users, who will want to compare one program to another, so they will need to be able to generate custom tables showing the outcomes for students. Tables will be something like this:
我正在开发一个使用PHP / SQL Server的应用程序,它需要存储来自大量不同学术课程的毕业生的信息,以及毕业后有多少人被雇用的信息......然后用户将要查询这些信息。将一个程序与另一个程序进行比较,因此他们需要能够生成显示学生成果的自定义表格。表格将是这样的:
Program Salary after 1 Year Salary after 2 Years Etc...
Engineering Lots Even more!
Philosophy Nothing Are you kidding me?
So, here's the question: should I store individual values for these data points in the database, or should I just store the raw HTML for the table row?
所以,这里有一个问题:我应该在数据库中存储这些数据点的单个值,还是应该只存储表行的原始HTML?
In other words, do I store this:
换句话说,我存储这个:
ProgramID Salary1 Salary2 Etc...
1 Lots Even More!
2 Nothing Are you kidding me?
Or do I store this:
或者我存储这个:
ProgramID RowHTML
1 <td>Lots</td><td>Even More!</td>...
2 <td>Nothing</td><td>Are you kidding me?</td>
I can see arguments for both approaches... my gut tells me that storing the raw HTML will be faster - it will eliminate GOBS of PHP processing. But I'm open to other interpretations.
我可以看到两种方法的论据......我的直觉告诉我存储原始HTML会更快 - 它将消除PHP处理的GOBS。但我愿意接受其他解释。
5 个解决方案
#1
3
Simple Rule for any RDBMS , only store the data in your tables and nothing else.
任何RDBMS的简单规则,只存储表中的数据而不存储任何其他内容。
This will make your data retrieval, updated and insert operations fast, simple and safe . Store data in your tables and create HTML tables on runtime. I have demonstrated here how easy and simple it is to create HTML tables when you have only data stored in your table and nothing else.
这将使您的数据检索,更新和插入操作快速,简单和安全。将数据存储在表中并在运行时创建HTML表。我在这里演示了当你只有数据存储在你的表中时,创建HTML表是多么容易和简单。
Example
I have used your given example
我用过你给出的例子
DECLARE @t TABLE (ProgramID INT,Salary1 VARCHAR(50),Salary2 VARCHAR(50))
INSERT INTO @t VALUES
(1,'Lots','Even More!'),
(2,'Nothing','Are you kidding me?')
DECLARE @tableHTML NVARCHAR(MAX) ;
SET @tableHTML =
N'<H1>Students Salaries</H1>' +
N'<table border="1">' +
N'<tr><th>ProgramID </th><th>Salary1</th><th>Salary2</th>' +
CAST ( ( SELECT td = ProgramID,
'',
td = Salary1,
'',
td = Salary2
FROM @t
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
N'</table>' ;
SELECT @tableHTML;
HTML Table Created by the above query
HTML表格由上述查询创建
<H1>Students Salaries</H1><table border="1"><tr><th>ProgramID </th><th>Salary1</th><th>Salary2</th><tr><td>1</td><td>Lots</td><td>Even More!</td></tr><tr><td>2</td><td>Nothing</td><td>Are you kidding me?</td></tr></table>
学生工资
ProgramID | Salary1 | Salary2 |
---|---|---|
1 | 很多 | 甚至更多! |
2 | 没什么 | 是你开玩笑吧? |
#2
0
I would store the raw data only. this will provide the ability to change the format/layout of the page when your boss says "Make it look newer" or whatever. If you store the table data, you are stuck.
我只存储原始数据。当你的老板说“让它看起来更新”或其他什么时,这将提供改变页面格式/布局的能力。如果存储表数据,则会卡住。
#3
0
i think that storing individual values for these data points in the database will be better for managing the application , HTML is good but when you work with PHP-DATAbase is better , ... good luck dude.
我认为在数据库中存储这些数据点的单个值对于管理应用程序会更好,HTML很好但是当你使用PHP-DATAbase时更好,...祝你好运。
#4
0
So, here's the question: should I store individual values for these data points in the database, or should I just store the raw HTML for the table row?
所以,这里有一个问题:我应该在数据库中存储这些数据点的单个值,还是应该只存储表行的原始HTML?
Straight answer:
Store the data points
, the html you can always recreate later, this will also make your queries way more fast.
存储数据点,您可以随时重新创建的html,这也将使您的查询更快。
#5
0
Short answer: Store the individual data, not the HTML.
简短回答:存储单个数据,而不是HTML。
There's no benefit to storing HTML here. Reproducing the table might be a little easier, but you're also storing a lot of redundant information, and building tables dynamically is not a difficult task to begin with. It's also much easier to manipulate raw data: when you're storing salaries over time as a single row of HTML, then you can only sort by program, but if you store each year individually and control the data type (your example salaries are strings, but you should be storing integers or floats, since you know that salary is an amount of money), you have the option of sorting programs by how much money graduates make out of college, ten years down the road, etc. Also bear in mind that you might not always want to display a table: you might want to graph the income over time for each major, for example, in which case you'd need to extract the salaries from the and tags, creating more work for yourself and slowing down the application.
这里存储HTML没有任何好处。重现表可能会更容易一些,但是您还要存储大量冗余信息,动态构建表并不是一件难事。操作原始数据也更容易:当您将工资随时间存储为单行HTML时,您只能按程序排序,但如果您每年存储一次并控制数据类型(您的示例工资是字符串) ,但你应该存储整数或浮点数,因为你知道工资是一笔金额),你可以选择按毕业生从大学毕业的金额,十年后的等等来分类计划。请注意,您可能并不总是想要显示一个表:您可能想要绘制每个专业的收入随时间变化,例如,在这种情况下,您需要从和标签中提取工资,为自己创建更多工作,放慢申请速度。
#1
3
Simple Rule for any RDBMS , only store the data in your tables and nothing else.
任何RDBMS的简单规则,只存储表中的数据而不存储任何其他内容。
This will make your data retrieval, updated and insert operations fast, simple and safe . Store data in your tables and create HTML tables on runtime. I have demonstrated here how easy and simple it is to create HTML tables when you have only data stored in your table and nothing else.
这将使您的数据检索,更新和插入操作快速,简单和安全。将数据存储在表中并在运行时创建HTML表。我在这里演示了当你只有数据存储在你的表中时,创建HTML表是多么容易和简单。
Example
I have used your given example
我用过你给出的例子
DECLARE @t TABLE (ProgramID INT,Salary1 VARCHAR(50),Salary2 VARCHAR(50))
INSERT INTO @t VALUES
(1,'Lots','Even More!'),
(2,'Nothing','Are you kidding me?')
DECLARE @tableHTML NVARCHAR(MAX) ;
SET @tableHTML =
N'<H1>Students Salaries</H1>' +
N'<table border="1">' +
N'<tr><th>ProgramID </th><th>Salary1</th><th>Salary2</th>' +
CAST ( ( SELECT td = ProgramID,
'',
td = Salary1,
'',
td = Salary2
FROM @t
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
N'</table>' ;
SELECT @tableHTML;
HTML Table Created by the above query
HTML表格由上述查询创建
<H1>Students Salaries</H1><table border="1"><tr><th>ProgramID </th><th>Salary1</th><th>Salary2</th><tr><td>1</td><td>Lots</td><td>Even More!</td></tr><tr><td>2</td><td>Nothing</td><td>Are you kidding me?</td></tr></table>
学生工资
ProgramID | Salary1 | Salary2 |
---|---|---|
1 | 很多 | 甚至更多! |
2 | 没什么 | 是你开玩笑吧? |
#2
0
I would store the raw data only. this will provide the ability to change the format/layout of the page when your boss says "Make it look newer" or whatever. If you store the table data, you are stuck.
我只存储原始数据。当你的老板说“让它看起来更新”或其他什么时,这将提供改变页面格式/布局的能力。如果存储表数据,则会卡住。
#3
0
i think that storing individual values for these data points in the database will be better for managing the application , HTML is good but when you work with PHP-DATAbase is better , ... good luck dude.
我认为在数据库中存储这些数据点的单个值对于管理应用程序会更好,HTML很好但是当你使用PHP-DATAbase时更好,...祝你好运。
#4
0
So, here's the question: should I store individual values for these data points in the database, or should I just store the raw HTML for the table row?
所以,这里有一个问题:我应该在数据库中存储这些数据点的单个值,还是应该只存储表行的原始HTML?
Straight answer:
Store the data points
, the html you can always recreate later, this will also make your queries way more fast.
存储数据点,您可以随时重新创建的html,这也将使您的查询更快。
#5
0
Short answer: Store the individual data, not the HTML.
简短回答:存储单个数据,而不是HTML。
There's no benefit to storing HTML here. Reproducing the table might be a little easier, but you're also storing a lot of redundant information, and building tables dynamically is not a difficult task to begin with. It's also much easier to manipulate raw data: when you're storing salaries over time as a single row of HTML, then you can only sort by program, but if you store each year individually and control the data type (your example salaries are strings, but you should be storing integers or floats, since you know that salary is an amount of money), you have the option of sorting programs by how much money graduates make out of college, ten years down the road, etc. Also bear in mind that you might not always want to display a table: you might want to graph the income over time for each major, for example, in which case you'd need to extract the salaries from the and tags, creating more work for yourself and slowing down the application.
这里存储HTML没有任何好处。重现表可能会更容易一些,但是您还要存储大量冗余信息,动态构建表并不是一件难事。操作原始数据也更容易:当您将工资随时间存储为单行HTML时,您只能按程序排序,但如果您每年存储一次并控制数据类型(您的示例工资是字符串) ,但你应该存储整数或浮点数,因为你知道工资是一笔金额),你可以选择按毕业生从大学毕业的金额,十年后的等等来分类计划。请注意,您可能并不总是想要显示一个表:您可能想要绘制每个专业的收入随时间变化,例如,在这种情况下,您需要从和标签中提取工资,为自己创建更多工作,放慢申请速度。