用户单击链接时如何在表中创建新字段 [英] How to make a new field in table when user clicks on a link

查看:46
本文介绍了用户单击链接时如何在表中创建新字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格如下图所示:

为了将表格中的数据插入表中,我对此进行了编码:

In order to insert data from this form into table I coded this:

// supplier info
$supplier_name = $_POST['supplier_name'];
$supplier_sending = $_POST['supplier_sending'];
$supplier_guarantee = $_POST['supplier_guarantee'];
$supplier_price = $_POST['supplier_price'];
$supplier_colors = $_POST['supplier_colors'];
$supplier_info = array($supplier_name, 
$supplier_sending,$supplier_guarantee, $supplier_price, $supplier_colors);
$proSupply = json_encode($supplier_info);

通过这种方式,我可以成功地将$proSupply var提交到我的表中.但正如您在打印屏幕中看到的那样,我添加了一个名为添加更多供应商:+ 的链接,它的作用基本上是在形式.因此,用户可以插入多个供应商信息.

By this way I can submit the $proSupply var successfully into my table. But as you can see in the print screen, I have added a link which is named Add more suppliers: + and what it does it basically adds a new table row to the form. So users can insert multiple supplier information.

但是问题是我的表上只有一个字段应包含供应商信息".而且因为我不知道用户要添加多少个供应商,所以我无法指定MySQL表中归档的供应商数量.

But the problem is there is only one field at my table which should contain the Supplier Info. And because I don't know how many supplier a user wants to add, I can not specify the amount of supplier filed in MySQL table.

所以我的问题是:每当用户单击PHP中的 + 链接(例如vendor_info_1,supplier_info_2等)时,是否可以在表中创建新的自定义字段?

So my question is: Is there any way to make a new custom field in table, whenever user clicks on the + link (For example supplier_info_1, supplier_info_2 & etc) within PHP ?

更新1 :

这是为我的表格表单提供新行的脚本.

This is the Script that provides a new row for my table form.

<script>
        $("#addbtn").click(function(){
            var next = parseInt($('#counter').val()) + 1;
            $("#group").append("<table class='table table-hover'>
                                 <tr>
                                     <th style='padding-left:10px'>Name of supplier ("+next+")</th>
                                     <th>Terms of sending</th>
                                     <th>Guarantee</th>
                                     <th>Price</th>
                                     <th>Colors (use , for separation)</th>
                                 </tr>
                                 <tr>
                                     <td style='padding-left:10px'><input name='supplier_name_("+next+")' type='text'></input></td>
                                     <td><input name='supplier_sending_("+next+")' type='text'></input></td>
                                     <td><input name='supplier_guarantee_("+next+")' type='text'></input></td>
                                     <td><input name='supplier_price_("+next+")' type='text'></input></td>
                                     <td><input name='supplier_colors_("+next+")' type='text'></input></td>
                                 </tr>
                                </table>");
            $('#counter').val(next);
        });
        </script>

推荐答案

是的,我在库存和会计软件中有类似的概念.您可以使用javascript或更佳地使用jquery来处理.您可以为供应商创建隐藏行.当基于您的应用程序触发事件时,将创建一个副本以获取另一个供应商行.

yes, i have a similar concept in my inventory and accounting software. you can use javascript or more preferably jquery to handle that. you can create a hidden row for a supplier. when an event is triggered base on your application, then a copy would be created to get another supplier row.

这篇关于用户单击链接时如何在表中创建新字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆