简体   繁体   English

最好使用页面上的表格或预制 javascript 变量中的数据 - PHP/Javascript

[英]Better to use data from table on page or from a pre-made javascript variable - PHP/Javascript

I found a few questions that were close, but not quite what I needed, so I'm sorry if this has already been asked.我发现了一些接近的问题,但不是我所需要的,所以如果已经有人问过,我很抱歉。

I have a page with a table filled in with PHP using data from a database.我有一个页面,其中的表格使用数据库中的数据填充了 PHP。 The user can select a row in the table and it will auto fill the data from that row into an edit section farther down the page.用户可以 select 表格中的一行,它会自动将该行的数据填充到页面下方的编辑部分。

My question is, when filling the edit fields, is it better to pull the data straight from the table or have PHP save the same data as the table in a javascript variable ahead of time and pull it from that?我的问题是,在填写编辑字段时,直接从表中提取数据还是让 PHP 提前将与表相同的数据保存在 javascript 变量中并从中提取数据更好?

When you want to edit the data you must access from the database and fill up the form, not by the js code cause it's bad practice.当您想要编辑数据时,您必须从数据库访问并填写表格,而不是通过 js 代码,因为这是不好的做法。

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

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