简体   繁体   English

动态行插入 - MySQL PHP - 怎么样?

[英]dynamic row inserts - MySQL PHP - how?

I have a misunderstanding regarding some dynamic row inserts in a MySQL table.我对 MySQL 表中的一些动态行插入有误解。

All I want to do is based on the EAV Model:我想做的只是基于EAV Model:

  • I have a products table which contains products我有一个包含产品的产品表
  • A attributes table which contains attributes (name) for products (group based - related to category)包含产品属性(名称)的属性表(基于组 - 与类别相关)
  • And a product_attribute which contains the value of the attribute还有一个 product_attribute 包含属性的值

And the user must create this attributes to be associated with a product, and I'm thinking to insert <input> elements with jQuery's append .并且用户必须创建此属性以与产品关联,我正在考虑使用 jQuery 的append插入<input>元素。

But how to track inserts and how to append them to have a specific name: <input name=''> .但是如何跟踪插入以及如何 append 它们具有特定名称: <input name=''>

The result should do the following:结果应执行以下操作:

<form action='attribute_insert.php' method='post'>
<input name='field1' />
<input name='field2' />
<input name='field3' />
....
<input name='field20' />
</form>

and after processing in attribute_insert.php to insert like this:并在attribute_insert.php处理后插入如下:

('1', '12', 'manufacturer');
('2', '12', 'freq');
('3', '12', 'memory');
('4', '12', 'ram');
....
('20', '12', 'blablabla');

How can I do this... using foreach to scan the $_POST[] or there is a clever method?我该怎么做...使用foreach扫描$_POST[]或者有一个聪明的方法?

Why not name them field[] , then you don't have to worry about the number.为什么不将它们命名为field[] ,那么您不必担心数字。 In PHP you can just do a for loop over $_POST['field'] , since it will return an array of the fields;)在 PHP 中,您可以在$_POST['field']上执行for循环,因为它将返回字段数组;)

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

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