php - 如何将动态添加的表单字段发布到mysql数据库

标签 php jquery mysql forms dynamic

我动态添加了表单字段,我需要将它们发布到数据库。

这是生成字段的jquery

                // set unique name for inputs
                .find('input').each(function(index) {
                    $(this).attr('name','input_'+ tr_length + '_' + (index + 1))
                })
                .end()
                // set unique name for selects
                .find('select').each(function(index) {
                    $(this).attr('name','select_'+ tr_length + '_' + (index + 1))
                });

这是输出

<input type="text" name="input_2_1" />

<select name="select_2_1"></select>

您能帮我将这些字段发布到数据库吗

问候

最佳答案

也许最好设置一个 EAV 表来处理此类数据。 EAV 的示例可能如下所示..

CREATE TABLE users(
  id int not null primary key auto_increment,
  email varchar(244) not null
);

CREATE TABLE user_attributes(
   id int not null primary key auto_increment,
   user_id int not null references users(id),
   attribute_name varchar(40) not null,
   attribute_value varchar(200) not null
);

检索用户数据.. SELECT * FROM users u JOIN user_attributes ua ON a.id=ua.user_id;

关于php - 如何将动态添加的表单字段发布到mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38217178/

相关文章:

javascript - 添加类后无法从元素中删除该类

php - 如何使用正则表达式通过 MySQL 查询返回记录?

mysql - hibernate + MySQL : How to set the encoding utf-8 for database and tables

php - 在什么情况下我们应该将类构造函数设为私有(private)

php:如何使用准备好的语句从sql数据库获取最新的日期时间?

javascript - 如何将append与getJSON一起使用

jquery - 简单的 Jquery 在 Firefox 16.0.2 中不起作用

mysql 根据字段值选择两个不同的表

php - 自动完成文本框下拉列表未出现在文本框下方

PHP ionCube 编码器文件不起作用